MOD = 1000000007

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

dp = [[0 for j in range(M+1)] for i in range(N+1)]
for i in range(N+1):
    dp[i][0] = 1
for j in range(M+1):
    dp[0][j] = 1

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

print(dp[-1][-1]) MOD = 1000000007 MOD 1000000007 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 [0 for j in range(M+1)] for i in range(N+1) for i in range(N+1) i range(N+1) range N+1 N 1 for i in range(N+1) [0 for j in range(M+1)] dp = [[0 for j in range(M+1)] for i in range(N+1)] dp [[0 for j in range(M+1)] for i in range(N+1)] for i in range(N+1):
    dp[i][0] = 1 i range(N+1) range N+1 N 1 dp[i][0] = 1 dp[i][0] [i] dp i 0 1 for j in range(M+1):
    dp[0][j] = 1 j range(M+1) range M+1 M 1 dp[0][j] = 1 dp[0][j] [0] dp 0 j 1 for i in range(N):
    for j in range(M):
        if S[i] == T[j]:
            dp[i+1][j+1] = dp[i+1][j]+dp[i][j+1]
        else:
            dp[i+1][j+1] = dp[i+1][j]+dp[i][j+1]-dp[i][j]
        dp[i+1][j+1] %= MOD i range(N) range N for j in range(M):
        if S[i] == T[j]:
            dp[i+1][j+1] = dp[i+1][j]+dp[i][j+1]
        else:
            dp[i+1][j+1] = dp[i+1][j]+dp[i][j+1]-dp[i][j]
        dp[i+1][j+1] %= MOD j range(M) range M if S[i] == T[j]:
            dp[i+1][j+1] = dp[i+1][j]+dp[i][j+1]
        else:
            dp[i+1][j+1] = dp[i+1][j]+dp[i][j+1]-dp[i][j]
         S[i] == T[j] S[i] S i T[j] T j dp[i+1][j+1] = dp[i+1][j]+dp[i][j+1] dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 dp[i+1][j]+dp[i][j+1] dp[i+1][j] [i+1] dp i+1 i 1 j dp[i][j+1] [i] dp i j+1 j 1 dp[i+1][j+1] = dp[i+1][j]+dp[i][j+1]-dp[i][j] dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 dp[i+1][j]+dp[i][j+1]-dp[i][j] dp[i+1][j]+dp[i][j+1] dp[i+1][j] [i+1] dp i+1 i 1 j dp[i][j+1] [i] dp i j+1 j 1 dp[i][j] [i] dp i j dp[i+1][j+1] %= MOD 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 N,M = map(int,input().split()) map(int,input().split()) N T = list(map(int,input().split())) list(map(int,input().split())) T MOD = 1000000007 1000000007 MOD S = list(map(int,input().split())) list(map(int,input().split())) S M = map(int,input().split()) map(int,input().split()) M dp = [[0 for j in range(M+1)] for i in range(N+1)] [[0 for j in range(M+1)] for i in range(N+1)] dp
MOD = 1000000007

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

dp = [[0 for j in range(M+1)] for i in range(N+1)]
for i in range(N+1):
    dp[i][0] = 1
for j in range(M+1):
    dp[0][j] = 1

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

print(dp[-1][-1])