n,m=map(x->parse(Int,x),split(readline()))
s=map(x->parse(Int,x),split(readline()))
t=map(x->parse(Int,x),split(readline()))
sum=ones(Int,m+1)
mod=10^9+7
for ss=s
	now=j=k=0
	for dp=[(j+=1;ss==tt?sum[j]%mod:0) for tt in t]
		k+=1
		sum[k+1]+=now+=dp
	end
end
println(sum[m+1]%mod)