MOD = 10**9 + 7
N, M = map(int, input().split(' '))
S = [0]
T = [0]
S += list(map(int, input().split(' ')))
T += list(map(int, input().split(' ')))
dp = [[0 for _ in range(M + 100)] for _ in range(N + 100)]
dp[0][0] = 1
total = [[0 for _ in range(M + 100)] for _ in range(N + 100)]
res = 1
for i in range(1, N + 1):
    for j in range(1, M + 1):
        if S[i] == T[j]:
            dp[i][j] = total[i-1][j-1] + 1
        else:
            dp[i][j] = 0
        total[i][j] = total[i-1][j] + total[i][j-1] - total[i-1][j-1] + dp[i][j]
        res += dp[i][j]
print(res % MOD)