from copy import deepcopy
mod = 10 ** 9 + 7
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
ans = [1 for i in range(m + 1)]
for i in s:
    ans2 = deepcopy(ans)
    cnt = 0
    for j in range(m):
        ans2[j] = (cnt + ans2[j]) % mod
        if i == t[j]:
            cnt = (cnt + ans[j]) % mod
    ans2[-1] = (cnt+ ans2[-1]) % mod
    ans = deepcopy(ans2)
print(ans[-1]) from copy import deepcopy mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m s = list(map(int, input().split())) s list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split t = list(map(int, input().split())) t list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split 1 for i in range(m + 1) for i in range(m + 1) i range(m + 1) range m + 1 m 1 for i in range(m + 1) 1 ans = [1 for i in range(m + 1)] ans [1 for i in range(m + 1)] for i in s:
    ans2 = deepcopy(ans)
    cnt = 0
    for j in range(m):
        ans2[j] = (cnt + ans2[j]) % mod
        if i == t[j]:
            cnt = (cnt + ans[j]) % mod
    ans2[-1] = (cnt+ ans2[-1]) % mod
    ans = deepcopy(ans2) i s ans2 = deepcopy(ans) ans2 deepcopy(ans) deepcopy ans cnt = 0 cnt 0 for j in range(m):
        ans2[j] = (cnt + ans2[j]) % mod
        if i == t[j]:
            cnt = (cnt + ans[j]) % mod
     j range(m) range m ans2[j] = (cnt + ans2[j]) % mod ans2[j] ans2 j (cnt + ans2[j]) % mod cnt + ans2[j] cnt ans2[j] ans2 j mod if i == t[j]:
            cnt = (cnt + ans[j]) % mod
     i == t[j] i t[j] t j cnt = (cnt + ans[j]) % mod cnt (cnt + ans[j]) % mod cnt + ans[j] cnt ans[j] ans j mod ans2[-1] = (cnt+ ans2[-1]) % mod ans2[-1] ans2 -1 (cnt+ ans2[-1]) % mod cnt+ ans2[-1] cnt ans2[-1] ans2 -1 mod ans = deepcopy(ans2) ans deepcopy(ans2) deepcopy ans2 print(ans[-1]) print ans[-1] ans -1 n, m = map(int, input().split()) map(int, input().split()) n s = list(map(int, input().split())) list(map(int, input().split())) s mod = 10 ** 9 + 7 10 ** 9 + 7 mod cnt = 0 0 cnt ans2 = deepcopy(ans) deepcopy(ans) ans2 m = map(int, input().split()) map(int, input().split()) m t = list(map(int, input().split())) list(map(int, input().split())) t ans = deepcopy(ans2) deepcopy(ans2) ans ans = [1 for i in range(m + 1)] [1 for i in range(m + 1)] ans cnt = (cnt + ans[j]) % mod (cnt + ans[j]) % mod cnt
from copy import deepcopy
mod = 10 ** 9 + 7
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
ans = [1 for i in range(m + 1)]
for i in s:
    ans2 = deepcopy(ans)
    cnt = 0
    for j in range(m):
        ans2[j] = (cnt + ans2[j]) % mod
        if i == t[j]:
            cnt = (cnt + ans[j]) % mod
    ans2[-1] = (cnt+ ans2[-1]) % mod
    ans = deepcopy(ans2)
print(ans[-1])