import numpy as np

MOD = 10 ** 9 + 7

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

dp = np.zeros(M, dtype=int)
dp_sum = np.zeros(M + 1, dtype=int)

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]

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

