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