from itertools import accumulate
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
mod = 10**9+7
dp = [0]*(N+1)
dp[0] = 1
for i, t in enumerate(T, 1):
    dp2 = dp[:]
    for i in range(1, N+1):
        dp2[i] = (dp2[i-1] + dp2[i]) % mod
    for j, s in enumerate(S, 1):
        if s == t:
            dp[j] += dp2[j-1]
ans = 0
for d in dp:
    ans = (ans + d) % mod
print(ans)