import numpy as np

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