MOD = (10**9) + 7

N, M = gets.chop.split.map(&:to_i)
SS = gets.chop.split.map(&:to_i)
TS = gets.chop.split.map(&:to_i)

dp = Array.new(N + 1, 0)
dp_sum = Array.new(N + 1, 1)
dp[0] = 1

t_num_hash = [*(0..2000)].group_by { |i| TS[i] }

SS.each do |num|
  nums = t_num_hash[num]
  next if nums.nil?
  nums.reverse.each do |i|
    dp[i + 1] = (dp[i + 1] + dp_sum[i]) % MOD
  end
  1.upto(N) do |i|
    dp_sum[i] = (dp_sum[i - 1] + dp[i]) % MOD
  end
end

puts dp.inject(0, &:+) % MOD
