N, M = map(int, input().split())
S = [int(i) for i in input().split()]
T = [int(i) for i in input().split()]
MOD = 10**9 + 7
ns = len(S)
nt = len(T)
dp = [[0] * (nt + 1) for i in range(ns + 1)]
for i in range(1, ns + 1):
    for j in range(1, nt + 1):
        if (S[i - 1] == T[j - 1]):
            dp[i][j] = 1 + dp[i][j - 1] + dp[i - 1][j]
        else:
            dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]
print((dp[ns][nt] + 1) % MOD)