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
	j=0
	now=0
	for dp=[ss==t[j]?sum[j]%mod:0 for j in 1:m]
		j+=1
		now+=dp
		sum[j+1]+=now
	end
end
println(sum[m+1]%mod)