n, m = gets.chomp.split(' ').map(&:to_i)
ss = gets.chomp.split(' ').map(&:to_i)
ts = gets.chomp.split(' ').map(&:to_i)
n_map = Array.new(n + 1).map{ Array.new(m + 1).map { [nil, nil, nil, nil] } }

# [0] が今までに終わったやつ、[1]がここで終わったやつ, [2] iだけ一緒、[3] jだけ一緒

for i in 0..n do
  n_map[i][0] = [0, 0, 0, 0]
end

for j in 0..m do
  n_map[0][j] = [0, 0, 0, 0]
end

for i in 1..n do
  for j in 1..m do
    n_map[i][j][0] = n_map[i - 1][j - 1].sum
    n_map[i][j][1] = ss[i - 1] == ts[j - 1] ? n_map[i - 1][j - 1].sum + 1 : 0
    n_map[i][j][2] = n_map[i][j - 1][1] + n_map[i][j - 1][2]
    n_map[i][j][3] = n_map[i - 1][j][1] + n_map[i - 1][j][3]
  end
end

n_results = n_map.map { |a| a.map{ |aa| aa[1] } }

sum = n_results.map { |a| a.sum }.sum

puts (sum + 1) % (10 ** 9 + 7)