n,m=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
mod=10**9+7
dp = [0]*m
for s in S:
    k=0
    d = [0]*(m+1)
    for i in range(m):
        if T[i]==s:
            k+=dp[i-1]+1
        d[i]=(dp[i]+k)%mod
    dp=d
print(dp[-2]+1)