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((N, M), dtype=int)
dp_sum = np.zeros((N + 1, M + 1), dtype=int)

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

print((np.sum(dp) + 1) % MOD)
