nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

import numpy as np
dp = np.zeros((N+1, M+1), dtype=np.int64)

for i, s in enumerate(S):
    dp[i+1, 1:] = dp[i, 1:] - dp[i, :M]
    for j, t in enumerate(T):
        dp[i+1, j+1] += dp[i+1, j]
        if s == t:
            dp[i+1, j+1] += dp[i, j] + 1

print(int(dp[N, M]+1) % 1000000007)
