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 j in range(1,1+M):
    dp[0][j]=dp[0][j-1]
for i in range(1,1+N):
    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):
        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
print(dp[N][M])