n,m=map(int,input().split())
s_list=[0]+list(map(int,input().split()))
t_list=[0]+list(map(int,input().split()))
dp=[]
for i in range(n+1):
    sub_list=[0]*(m+1)
    dp.append(sub_list)
for j in range(m+1):
    dp[0][j]=1
for i in range(n+1):
    dp[i][0]=1
Mod=10**9+7
for i in range(1,n+1):
    for j in range(1,m+1):
        if s_list[i]==t_list[j]:
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%Mod
        else:
            dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%Mod
print(dp[n][m])



