N, M = map(int, input().split())
S = tuple(map(int, input().split()))
T = tuple(map(int, input().split()))
MOD = 10 ** 9 + 7

dp = [[1] * (M + 1) for _ in range(N + 1)]
for i in range(N):
    for j in range(M):
        dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j]
        if S[i] != T[j]:
            dp[i + 1][j + 1] -= dp[i][j]
        dp[i + 1][j + 1] %= MOD
print(dp[N][M]) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M S = tuple(map(int, input().split())) S tuple(map(int, input().split())) tuple map(int, input().split()) map int input().split() ().split () input split T = tuple(map(int, input().split())) T tuple(map(int, input().split())) tuple map(int, input().split()) map int input().split() ().split () input split MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 [1] * (M + 1) for _ in range(N + 1) for _ in range(N + 1) _ range(N + 1) range N + 1 N 1 for _ in range(N + 1) [1] * (M + 1) [1] 1 M + 1 M 1 dp = [[1] * (M + 1) for _ in range(N + 1)] dp [[1] * (M + 1) for _ in range(N + 1)] for i in range(N):
    for j in range(M):
        dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j]
        if S[i] != T[j]:
            dp[i + 1][j + 1] -= dp[i][j]
        dp[i + 1][j + 1] %= MOD i range(N) range N for j in range(M):
        dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j]
        if S[i] != T[j]:
            dp[i + 1][j + 1] -= dp[i][j]
        dp[i + 1][j + 1] %= MOD j range(M) range M dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] dp[i + 1][j + 1] [i + 1] dp i + 1 i 1 j + 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 if S[i] != T[j]:
            dp[i + 1][j + 1] -= dp[i][j]
         S[i] != T[j] S[i] S i T[j] T j dp[i + 1][j + 1] -= dp[i][j] dp[i + 1][j + 1] [i + 1] dp i + 1 i 1 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[N][M]) print dp[N][M] [N] dp N M T = tuple(map(int, input().split())) tuple(map(int, input().split())) T M = map(int, input().split()) map(int, input().split()) M N, M = map(int, input().split()) map(int, input().split()) N dp = [[1] * (M + 1) for _ in range(N + 1)] [[1] * (M + 1) for _ in range(N + 1)] dp S = tuple(map(int, input().split())) tuple(map(int, input().split())) S MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD
N, M = map(int, input().split())
S = tuple(map(int, input().split()))
T = tuple(map(int, input().split()))
MOD = 10 ** 9 + 7

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