$mod = 1000000007
N,M=gets.chomp.split(' ').map{|n| n.to_i}
S=gets.chomp.split(' ').map{|n| n.to_i}
T=gets.chomp.split(' ').map{|n| n.to_i}

DP = Array.new(N) { Array.new(M) { |i| 0 }  }
SUM = Array.new(M){ 0 }
SUMmin1 = Array.new(M) { |i| 0 }
for s in 0..(N-1)
	SUMmin1[0] = SUM[0]
	if(S[s]==T[0])
		DP[s][0] = 1
		SUM[0] += 1
	end
	for t in 1..(M-1)
		DP[s][t] = DP[s][t-1]
		if(S[s]==T[t])
			#match
			DP[s][t] += SUMmin1[t-1]+1
		end
		SUMmin1[t] = SUM[t]
		SUM[t] += DP[s][t]
	end
	# puts "SUMMIN1"
	# p SUMmin1
	# puts "SUM"
	# p SUM
	# p DP
end
# p SUM
# p DP
puts (SUM[M-1]+1 )% $mod

