require 'pp'

N,M = readline.chomp.split.map(&:to_i)
S = readline.chomp.split.map(&:to_i)
T = readline.chomp.split.map(&:to_i)
MOD = 1_000_000_007

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

(1..N).each do |n|
  (1..M).each do |m|
    dp[n][m] = dp[n][m-1]
    x = T[m-1]
    S.each_with_index do |s,i|
      break if i > n-1
      if s == x
        dp[n][m] += 1 + dp[i][m-1]
      end
    end
    dp[n][m] = dp[n][m] % MOD
  end
end

puts dp[N][M]+1

