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