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