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