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

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

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

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

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

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

print(sm[N][M])
