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()))
dp=zeros(Int,n+1,m+1)
sum=zeros(Int,n+1,m+1)
mod=10^9+7
for j=1:m+1;sum[1,j]=1;end
for i=1:n
	for j=1:m
		if s[i]==t[j]
			dp[i+1,j+1]=sum[i,j]
		end
	end
	now=0
	for j=1:m+1
		now=(now+dp[i+1,j])%mod
		sum[i+1,j]=sum[i,j]+now
	end
end
println(sum[n+1,m+1]%mod)