n, m = map(int, input().split())
s = list(map(int, input().split())) + [0]
t = list(map(int, input().split())) + [0]
MOD = 10 ** 9 + 7
dp = [[[0, 0] for j in range(m + 2)] for i in range(n + 2)]
for i, si in enumerate(s):
    for j, tj in enumerate(t):
        if si == tj:
            dp[i + 1][j + 1][0] = (dp[i][j][1] + 1) % MOD
        dp[i + 1][j + 1][1] = (dp[i + 1][j][1] + dp[i][j + 1][1] - dp[i][j][1] + dp[i + 1][j + 1][0]) % MOD
print(dp[-1][-1][0])
