import numpy as np

md=10**9+7
n,m=map(int,input().split())
s=list(input().split())
t=list(input().split())
dp=np.zeros((n+1,m+1),dtype="i8")
dp[0][0]=1
for i,sk in enumerate(s):
    for j,tk in enumerate(t):
        if sk==tk:
            dp[i+1][j+1]=np.sum(dp[:i+1,:j+1])%md
print(np.sum(dp)%md)