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