def inpl(): return list(map(int, input().split()))
MOD = 10**9 + 7
N, M = inpl()
S = [0] + inpl()
T = [0] + inpl()

DP = [[1]*(N+1) for _ in range(M+1)]

for i in range(1, M+1):
    for j in range(1, N+1):
        if S[j] == T[i]:
            DP[i][j] = (DP[i][j-1] + DP[i-1][j])%MOD
        else:
            DP[i][j] = (DP[i][j-1] + DP[i-1][j] - DP[i-1][j-1])%MOD
print(DP[-1][-1]) def inpl(): return list(map(int, input().split())) inpl MOD = 10**9 + 7 MOD 10**9 + 7 10**9 10 9 7 N, M = inpl() N inpl() inpl M S = [0] + inpl() S [0] + inpl() [0] 0 inpl() inpl T = [0] + inpl() T [0] + inpl() [0] 0 inpl() inpl [1]*(N+1) for _ in range(M+1) for _ in range(M+1) _ range(M+1) range M+1 M 1 for _ in range(M+1) [1]*(N+1) [1] 1 N+1 N 1 DP = [[1]*(N+1) for _ in range(M+1)] DP [[1]*(N+1) for _ in range(M+1)] for i in range(1, M+1):
    for j in range(1, N+1):
        if S[j] == T[i]:
            DP[i][j] = (DP[i][j-1] + DP[i-1][j])%MOD
        else:
            DP[i][j] = (DP[i][j-1] + DP[i-1][j] - DP[i-1][j-1])%MOD i range(1, M+1) range 1 M+1 M 1 for j in range(1, N+1):
        if S[j] == T[i]:
            DP[i][j] = (DP[i][j-1] + DP[i-1][j])%MOD
        else:
            DP[i][j] = (DP[i][j-1] + DP[i-1][j] - DP[i-1][j-1])%MOD j range(1, N+1) range 1 N+1 N 1 if S[j] == T[i]:
            DP[i][j] = (DP[i][j-1] + DP[i-1][j])%MOD
        else:
            DP[i][j] = (DP[i][j-1] + DP[i-1][j] - DP[i-1][j-1])%MOD S[j] == T[i] S[j] S j T[i] T i DP[i][j] = (DP[i][j-1] + DP[i-1][j])%MOD DP[i][j] [i] DP i j (DP[i][j-1] + DP[i-1][j])%MOD DP[i][j-1] + DP[i-1][j] DP[i][j-1] [i] DP i j-1 j 1 DP[i-1][j] [i-1] DP i-1 i 1 j MOD DP[i][j] = (DP[i][j-1] + DP[i-1][j] - DP[i-1][j-1])%MOD DP[i][j] [i] DP i j (DP[i][j-1] + DP[i-1][j] - DP[i-1][j-1])%MOD DP[i][j-1] + DP[i-1][j] - DP[i-1][j-1] DP[i][j-1] + DP[i-1][j] DP[i][j-1] [i] DP i j-1 j 1 DP[i-1][j] [i-1] DP i-1 i 1 j DP[i-1][j-1] [i-1] DP i-1 i 1 j-1 j 1 MOD print(DP[-1][-1]) print DP[-1][-1] [-1] DP -1 -1 S = [0] + inpl() [0] + inpl() S M = inpl() inpl() M N, M = inpl() inpl() N DP = [[1]*(N+1) for _ in range(M+1)] [[1]*(N+1) for _ in range(M+1)] DP T = [0] + inpl() [0] + inpl() T def inpl(): return list(map(int, input().split())) def inpl(): return list(map(int, input().split())) inpl MOD = 10**9 + 7 10**9 + 7 MOD
def inpl(): return list(map(int, input().split()))
MOD = 10**9 + 7
N, M = inpl()
S = [0] + inpl()
T = [0] + inpl()

DP = [[1]*(N+1) for _ in range(M+1)]

for i in range(1, M+1):
    for j in range(1, N+1):
        if S[j] == T[i]:
            DP[i][j] = (DP[i][j-1] + DP[i-1][j])%MOD
        else:
            DP[i][j] = (DP[i][j-1] + DP[i-1][j] - DP[i-1][j-1])%MOD
print(DP[-1][-1])