N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))

A = []
B = []
mod = 10**9 + 7

for i in range(N):
    if S[i] in T:
        A.append(S[i])

for i in range(M):
    if T[i] in S:
        B.append(T[i])        
        
l1 = [1] * (N + 1)

for i, t in enumerate(T):
    l2 = l1[:]
    k = 0
    for j, s in enumerate(S):
        if t == s:
            k += l1[j]
        l2[j + 1] = (l1[j + 1] + k) % mod
    l1 = l2
print(l1[-1]) 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 A = [] A [] B = [] B [] mod = 10**9 + 7 mod 10**9 + 7 10**9 10 9 7 for i in range(N):
    if S[i] in T:
        A.append(S[i]) i range(N) range N if S[i] in T:
        A.append(S[i]) S[i] in T S[i] S i T A.append(S[i]) A.append A append S[i] S i for i in range(M):
    if T[i] in S:
        B.append(T[i])        
         i range(M) range M if T[i] in S:
        B.append(T[i])        
         T[i] in S T[i] T i S B.append(T[i]) B.append B append T[i] T i l1 = [1] * (N + 1) l1 [1] * (N + 1) [1] 1 N + 1 N 1 for i, t in enumerate(T):
    l2 = l1[:]
    k = 0
    for j, s in enumerate(S):
        if t == s:
            k += l1[j]
        l2[j + 1] = (l1[j + 1] + k) % mod
    l1 = l2 i t enumerate(T) enumerate T l2 = l1[:] l2 l1[:] l1 : k = 0 k 0 for j, s in enumerate(S):
        if t == s:
            k += l1[j]
        l2[j + 1] = (l1[j + 1] + k) % mod
     j s enumerate(S) enumerate S if t == s:
            k += l1[j]
         t == s t s k += l1[j] k l1[j] l1 j l2[j + 1] = (l1[j + 1] + k) % mod l2[j + 1] l2 j + 1 j 1 (l1[j + 1] + k) % mod l1[j + 1] + k l1[j + 1] l1 j + 1 j 1 k mod l1 = l2 l1 l2 print(l1[-1]) print l1[-1] l1 -1 l1 = l2 l2 l1 S = list(map(int, input().split())) list(map(int, input().split())) S l1 = [1] * (N + 1) [1] * (N + 1) l1 N, M = map(int, input().split()) map(int, input().split()) N M = map(int, input().split()) map(int, input().split()) M A = [] [] A T = list(map(int, input().split())) list(map(int, input().split())) T k = 0 0 k l2 = l1[:] l1[:] l2 mod = 10**9 + 7 10**9 + 7 mod k += l1[j] l1[j] k B = [] [] B
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))

A = []
B = []
mod = 10**9 + 7

for i in range(N):
    if S[i] in T:
        A.append(S[i])

for i in range(M):
    if T[i] in S:
        B.append(T[i])        
        
l1 = [1] * (N + 1)

for i, t in enumerate(T):
    l2 = l1[:]
    k = 0
    for j, s in enumerate(S):
        if t == s:
            k += l1[j]
        l2[j + 1] = (l1[j + 1] + k) % mod
    l1 = l2
print(l1[-1])