n = gets.split.map(&:to_i)
s = gets.split.map(&:to_i)
t = gets.split.map(&:to_i)
dp = Array.new(n[0]+1).map{Array.new(n[1]+1,0)}
sum = Array.new(n[0]+1).map{Array.new(n[1]+1,0)}
for i in 1..n[0]
  for j in 1..n[1]
    if s[i-1] == t[j-1]
      dp[i][j] = sum[i-1][j-1] + 1
    else
      dp[i][j] = 0
    end
    sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + dp[i][j]
  end
end
puts (sum[-1][-1]+1) % (10**9 + 7)
