md=10**9+7
n,m=map(int,input().split())
s=list(input().split())
t=list(input().split())
dp=[[1]*(m+1) for _ in range(n+1)]
for i,sk in enumerate(s):
    dp[i+1]=dp[i][:]
    cs=0
    for j,tk in enumerate(t):
        if sk==tk:
            cs+=dp[i][j]
        dp[i+1][j+1]+=cs
print(dp[-1][-1]%md)