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