N,M=gets.split.map(&:to_i)
as=gets.split.map(&:to_i)
bs=gets.split.map(&:to_i)
MOD=1000000007
as.unshift(nil)
bs.unshift(nil)
dp=Array.new(N+1){Array.new(M+1,1)}
1.upto(N) do |i|
  1.upto(M) do |j|
    if as[i]==bs[j]
      dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD
    else
      dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%MOD
    end
  end
end
puts dp[N][M]%MOD