parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	mod = 1000000007
	n,m = readline() |> split |> parseMap
	s = readline() |> split |> parseMap
	t = readline() |> split |> parseMap
	dp = zeros(Int,n+1,m+1)
	dp[1,:] = 1
	dp[:,1] = 1
	for i in 1:n
		dp[i+1,:] = dp[i,:]
		for j in 1:m
			if s[i] == t[j]
				dp[i+1,j+1] = (dp[i,j+1]+dp[i+1,j])%mod
			else
				dp[i+1,j+1] = (dp[i,j+1]+dp[i+1,j]-dp[i,j])%mod
			end
		end
	end
	println(dp[n+1,m+1])
end

main()