mod=10**9+7
N,M=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
dp=[[0]*(M+1) for i in range(N+1)]
from collections import defaultdict
data=[defaultdict(int) for i in range(M+1)]
dp[0][0]=1
for i in range(1+N):
    if i>0:
        dp[i][0]=dp[i-1][0]
        data[0][S[i-1]]=(data[0][S[i-1]]+dp[i][0])%mod
    for j in range(1,1+M):
        if i>0 and j>0:
            data[j][S[i-1]]=(data[j][S[i-1]]+dp[i-1][j])%mod
            dp[i][j]=(data[j-1][T[j-1]]+dp[i][j-1])%mod
        elif j>0:
            dp[i][j]=dp[i][j-1]
print(dp[N][M])