n, m = gets.chomp.split.map &:to_i
s = gets.chomp.split.map &:to_i
t = gets.chomp.split.map &:to_i
dp = Array.new(n+1){Array.new(m,0)}
(n).times do |i|
  (m).times do |j|
    if(s[i] == t[j])
      dp[i][j] += 1
    end
  end
end
puts dp.flatten.count(1)
#TLETEST