MOD=10**9+7

N,M=map(int,input().split())
slist=list(map(int,input().split()))
tlist=list(map(int,input().split()))

dp=[]
for i in range(N+1):
  dp.append([0]*(M+1))
dp[0][0]=1
#print(dp)

answer=1
for i in range(1,N+1):
  for j in range(1,M+1):
    if slist[i-1]==tlist[j-1]:
      for ii in range(i):
        for jj in range(j):
          dp[i][j]+=dp[ii][jj]
          answer+=dp[ii][jj]
          answer%=MOD

#print(dp)
print(answer)