MOD = 10 ** 9 + 7
def max(a,b); a > b ? a : b; end

N, M = gets.split.map(&:to_i)
S = gets.split.map(&:to_i)
T = gets.split.map(&:to_i)

dp = Array.new(N + 1){Array.new(M + 1, 0)}
dp[0][0] = 1
(1 .. N).each{|i| dp[i][0] = 1}
(1 .. M).each{|j| dp[0][j] = 1}

(1 .. N).each do |i|
  (1 .. M).each do |j|
    if S[i-1] == T[j-1]
      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]
