N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
ans = 0
mod = 10**9+7
C = [1]*(N+1)
for t in T:
    d = 0
    for i, s in enumerate(S):
        d_ = C[i]
        if t==s:
            ans = (ans + d_) % mod

        C[i] += d
        C[i] %= mod
        if t==s:
            d += d_
            d %= mod
print(ans+1)
