(N, M), Ss, Ts = readlines.map{|l| l.split.map(&:to_i)}
MOD = 10**9 + 7

dp = Array.new(N + 1){Array.new(M + 1, 0)}
(N + 1).times{|i| dp[i][0] = 1}
(M + 1).times{|j| dp[0][j] = 1}
(1 .. N).each do |i|
  (1 .. M).each do |j|
    dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - (Ss[i - 1] == Ts[j - 1] ? 0 : dp[i - 1][j - 1])) % MOD
  end
end
puts dp[-1][-1]