import sys
sys.setrecursionlimit(10**6+32)
from functools import lru_cache
mod=10**9+7
n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
#dp=[ [0 for _ in range(m)] for _ in range(n)]
@lru_cache(None)
def solve(i,j):
    if i==0 and j==0:
        if s[i]==t[j]:
            return 1
        else:
            return 0
    if i<0 or j<0:
        return 0
    ret=0
    ret=solve(i-1,j)+solve(i,j-1)-solve(i-1,j-1)
    ret%=mod
    if s[i]==t[j]:
        ret+=1+solve(i-1,j-1)
    return ret%mod
print((solve(n-1,m-1)+1)%mod)

