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(M+1, dtype=np.int64)
for i, s in enumerate(S):
    dp2 = np.zeros(M+1, dtype=np.int64)
    dp2[1:] = dp[1:] - dp[:M]
    for j, t in enumerate(T):
        dp2[j+1] += dp2[j]
        if s == t:
            dp2[j+1] += dp[j] + 1
    dp = dp2

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