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