MOD = 10 ** 9 + 7

N, M = map(int, input().split())
S, T = list(input().split()), list(input().split())

dp, dp_sum = [0] * M, [0] * (M + 1)

for i in range(N):
    for j in range(M):
        if S[i] == T[j]:
            dp[j] = dp_sum[j + 1] + 1
        dp_sum[j + 1] = (dp_sum[j] + dp[j]) % MOD

print((dp_sum[M] + 1) % MOD)
