from copy import deepcopy as de
n,m =[int(i) for i in input().split()]
s=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]
a=[1]*(m+1)
for i,b in enumerate(s):
  d=de(a)
  k=0
  for j,c in enumerate(t):
    d[j]+=k
    if b==c:
      k+=a[j]
  d[-1]+=k
  a=de(d)
print(a[-1]%1000000007)
    
