mod=10**9+7
n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
dp1=[1]*(m+1)
dp2=[1]*(m+1)
for i in range(n):
  if i%2==0:
    for j in range(m):
      if s[i]==t[j]:dp1[j+1]=dp2[j+1]+dp1[j]
      else:dp1[j+1]=dp2[j+1]+dp1[j]-dp2[j]
      dp1[j+1]%=mod
  else:
    for j in range(m):
      if s[i]==t[j]:dp2[j+1]=dp1[j+1]+dp2[j]
      else:dp2[j+1]=dp1[j+1]+dp2[j]-dp1[j]
      dp2[j+1]%=mod
if n%2==0:print(dp2[-1])
else:print(dp1[-1])