N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [1] * (M+1)
dpleft = [0] * (M)
MOD = 10 ** 9 + 7
ndp = [1] * (M+1)
for n in range(N):
    for m in range(M):
        if S[n] == T[m]:
            ndp[m+1] = (ndp[m] + dp[m+1]) % MOD
            dpleft[m] = dp[m+1]
        else:
            ndp[m+1] = (ndp[m] + dpleft[m]) % MOD
        dp[m] = ndp[m]
    dp[-1] = ndp[-1]
print(dp[-1]) 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 dp = [1] * (M+1) dp [1] * (M+1) [1] 1 M+1 M 1 dpleft = [0] * (M) dpleft [0] * (M) [0] 0 M MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 ndp = [1] * (M+1) ndp [1] * (M+1) [1] 1 M+1 M 1 for n in range(N):
    for m in range(M):
        if S[n] == T[m]:
            ndp[m+1] = (ndp[m] + dp[m+1]) % MOD
            dpleft[m] = dp[m+1]
        else:
            ndp[m+1] = (ndp[m] + dpleft[m]) % MOD
        dp[m] = ndp[m]
    dp[-1] = ndp[-1] n range(N) range N for m in range(M):
        if S[n] == T[m]:
            ndp[m+1] = (ndp[m] + dp[m+1]) % MOD
            dpleft[m] = dp[m+1]
        else:
            ndp[m+1] = (ndp[m] + dpleft[m]) % MOD
        dp[m] = ndp[m]
     m range(M) range M if S[n] == T[m]:
            ndp[m+1] = (ndp[m] + dp[m+1]) % MOD
            dpleft[m] = dp[m+1]
        else:
            ndp[m+1] = (ndp[m] + dpleft[m]) % MOD
         S[n] == T[m] S[n] S n T[m] T m ndp[m+1] = (ndp[m] + dp[m+1]) % MOD ndp[m+1] ndp m+1 m 1 (ndp[m] + dp[m+1]) % MOD ndp[m] + dp[m+1] ndp[m] ndp m dp[m+1] dp m+1 m 1 MOD dpleft[m] = dp[m+1] dpleft[m] dpleft m dp[m+1] dp m+1 m 1 ndp[m+1] = (ndp[m] + dpleft[m]) % MOD ndp[m+1] ndp m+1 m 1 (ndp[m] + dpleft[m]) % MOD ndp[m] + dpleft[m] ndp[m] ndp m dpleft[m] dpleft m MOD dp[m] = ndp[m] dp[m] dp m ndp[m] ndp m dp[-1] = ndp[-1] dp[-1] dp -1 ndp[-1] ndp -1 print(dp[-1]) print dp[-1] dp -1 M = map(int, input().split()) map(int, input().split()) M dp = [1] * (M+1) [1] * (M+1) dp S = list(map(int, input().split())) list(map(int, input().split())) S MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD dpleft = [0] * (M) [0] * (M) dpleft ndp = [1] * (M+1) [1] * (M+1) ndp N, M = map(int, input().split()) map(int, input().split()) N T = list(map(int, input().split())) list(map(int, input().split())) T
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [1] * (M+1)
dpleft = [0] * (M)
MOD = 10 ** 9 + 7
ndp = [1] * (M+1)
for n in range(N):
    for m in range(M):
        if S[n] == T[m]:
            ndp[m+1] = (ndp[m] + dp[m+1]) % MOD
            dpleft[m] = dp[m+1]
        else:
            ndp[m+1] = (ndp[m] + dpleft[m]) % MOD
        dp[m] = ndp[m]
    dp[-1] = ndp[-1]
print(dp[-1])