import itertools
import numpy as np
n,m=map(int,input().split()) #<=2*10**3
#n
s=list(map(int,input().split()))
#m
t=list(map(int,input().split()))
mod=10**9+7
ans=np.zeros(m,dtype="int64")

for u in s:
    h=np.zeros(m,dtype="int64")
    if u==t[0]:
        h[0]+=1
    for i in range(1,m):
        if t[i]==u:
            h[i]+=ans[i-1]+1
        h[i]+=h[i-1]
    ans=(ans+h)%mod
print(ans[-1]+1)