n, m = map(int, input().split())
mod = 10 ** 9 + 7

dp = [[1] * (n + 1)] + [[1] + [0] * n for _ in range(m)]

arr_s = [0] + list(map(int, input().split()))
arr_t = [0] + list(map(int, input().split()))

for r in range(1, m + 1):
    for c in range(1, n + 1):
        if arr_s[c] == arr_t[r]:
            dp[r][c] = dp[r-1][c] + dp[r][c-1]
        else:
            dp[r][c] = dp[r-1][c] + dp[r][c-1] - dp[r-1][c-1]
        dp[r][c] %= mod

print(dp[m][n])
