N,M = list(map(int,input().split()))
S = list(map(int,input().split()))
S = [0] + S
T = list(map(int,input().split()))
T = [0] + T
dp = [[0] * (N+1)  for _ in range(M+1)]
DP = [[0] * (N+1)  for _ in range(M+1)]
dp[0][0] = 1
for n in range(N+1):
    DP[0][n] = 1
for m in range(M+1):
    DP[m][0] = 1
# s = 0
# for i in range(N+1):
#     for j in range(M+1):
#         if S[i] == T[j]:
#             for i2 in range(i):
#                 for j2 in range(j):
#                     dp[i][j] += dp[i2][j2]
#             s += dp[i][j]
# print(s)
for n in range(1,N+1):
    for m in range(1,M+1):
        if S[n] == T[m]:
            dp[m][n] = DP[m-1][n-1]
        DP[m][n] = (DP[m-1][n] + DP[m][n-1] + dp[m][n] - DP[m-1][n-1]) % (10**9+7)
print(DP[M][N]) N,M = list(map(int,input().split())) N list(map(int,input().split())) list 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 S = [0] + S S [0] + S [0] 0 S T = list(map(int,input().split())) T list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split T = [0] + T T [0] + T [0] 0 T [0] * (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) [0] * (N+1) [0] 0 N+1 N 1 dp = [[0] * (N+1)  for _ in range(M+1)] dp [[0] * (N+1)  for _ in range(M+1)] [0] * (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) [0] * (N+1) [0] 0 N+1 N 1 DP = [[0] * (N+1)  for _ in range(M+1)] DP [[0] * (N+1)  for _ in range(M+1)] dp[0][0] = 1 dp[0][0] [0] dp 0 0 1 for n in range(N+1):
    DP[0][n] = 1 n range(N+1) range N+1 N 1 DP[0][n] = 1 DP[0][n] [0] DP 0 n 1 for m in range(M+1):
    DP[m][0] = 1
# s = 0
# for i in range(N+1):
#     for j in range(M+1):
#         if S[i] == T[j]:
#             for i2 in range(i):
#                 for j2 in range(j):
#                     dp[i][j] += dp[i2][j2]
#             s += dp[i][j]
# print(s) m range(M+1) range M+1 M 1 DP[m][0] = 1 DP[m][0] [m] DP m 0 1 for n in range(1,N+1):
    for m in range(1,M+1):
        if S[n] == T[m]:
            dp[m][n] = DP[m-1][n-1]
        DP[m][n] = (DP[m-1][n] + DP[m][n-1] + dp[m][n] - DP[m-1][n-1]) % (10**9+7) n range(1,N+1) range 1 N+1 N 1 for m in range(1,M+1):
        if S[n] == T[m]:
            dp[m][n] = DP[m-1][n-1]
        DP[m][n] = (DP[m-1][n] + DP[m][n-1] + dp[m][n] - DP[m-1][n-1]) % (10**9+7) m range(1,M+1) range 1 M+1 M 1 if S[n] == T[m]:
            dp[m][n] = DP[m-1][n-1]
         S[n] == T[m] S[n] S n T[m] T m dp[m][n] = DP[m-1][n-1] dp[m][n] [m] dp m n DP[m-1][n-1] [m-1] DP m-1 m 1 n-1 n 1 DP[m][n] = (DP[m-1][n] + DP[m][n-1] + dp[m][n] - DP[m-1][n-1]) % (10**9+7) DP[m][n] [m] DP m n (DP[m-1][n] + DP[m][n-1] + dp[m][n] - DP[m-1][n-1]) % (10**9+7) DP[m-1][n] + DP[m][n-1] + dp[m][n] - DP[m-1][n-1] DP[m-1][n] + DP[m][n-1] + dp[m][n] DP[m-1][n] + DP[m][n-1] DP[m-1][n] [m-1] DP m-1 m 1 n DP[m][n-1] [m] DP m n-1 n 1 dp[m][n] [m] dp m n DP[m-1][n-1] [m-1] DP m-1 m 1 n-1 n 1 10**9+7 10**9 10 9 7 print(DP[M][N]) print DP[M][N] [M] DP M N N,M = list(map(int,input().split())) list(map(int,input().split())) N M = list(map(int,input().split())) list(map(int,input().split())) M DP = [[0] * (N+1)  for _ in range(M+1)] [[0] * (N+1)  for _ in range(M+1)] DP S = [0] + S [0] + S S T = list(map(int,input().split())) list(map(int,input().split())) T S = list(map(int,input().split())) list(map(int,input().split())) S T = [0] + T [0] + T T dp = [[0] * (N+1)  for _ in range(M+1)] [[0] * (N+1)  for _ in range(M+1)] dp
N,M = list(map(int,input().split()))
S = list(map(int,input().split()))
S = [0] + S
T = list(map(int,input().split()))
T = [0] + T
dp = [[0] * (N+1)  for _ in range(M+1)]
DP = [[0] * (N+1)  for _ in range(M+1)]
dp[0][0] = 1
for n in range(N+1):
    DP[0][n] = 1
for m in range(M+1):
    DP[m][0] = 1
# s = 0
# for i in range(N+1):
#     for j in range(M+1):
#         if S[i] == T[j]:
#             for i2 in range(i):
#                 for j2 in range(j):
#                     dp[i][j] += dp[i2][j2]
#             s += dp[i][j]
# print(s)
for n in range(1,N+1):
    for m in range(1,M+1):
        if S[n] == T[m]:
            dp[m][n] = DP[m-1][n-1]
        DP[m][n] = (DP[m-1][n] + DP[m][n-1] + dp[m][n] - DP[m-1][n-1]) % (10**9+7)
print(DP[M][N])