gets
elems = gets.chomp.split.map(&:to_i)
gets
query = gets.chomp.split.map(&:to_i)

def bsearch(q, elems)
    mid = elems.length / 2
    if elems[mid] == q then
        1
    elsif elems.length == 1
        0
    elsif elems[mid] > q
        bsearch(q, elems[0...mid])
    else
        bsearch(q, elems[mid...elems.length])
    end
end

sum = query.reduce(0) do |acc, q|
    acc += bsearch(q, elems)
end

p sum
