from functools import lru_cache
N,M = map(int,input().split())
S = tuple(map(int,input().split()))
T = tuple(map(int,input().split()))
MOD = 10**9 + 7

dp = [1]*(M+1)

for i,s in enumerate(S, start=1):
    ndp = [None]*(M+1)
    ndp[0] = 1
    for j,t in enumerate(T, start=1):
        if s == t:
            ndp[j] = dp[j]+ndp[j-1]
        else:
            ndp[j] = dp[j]+ndp[j-1]-dp[j-1]
    dp = ndp

print(ndp[-1]%MOD)
