gets
a = gets.split(' ').map(&:to_i)
gets
b = gets.split(' ').map(&:to_i)
def binary_search(a,b)
  count = 0
  left = 0
  right = a.length
  b.each do |key|
    while left < right
      mid = (left + right)/2
      if a[mid] == key
        count += 1
        break
      elsif a[mid] < key
        left = mid + 1
      else
        right = mid
      end
    end
  end
  count
end
puts binary_search(a,b)