N = gets.to_i persons = N.times.map { gets.split.map(&:to_i) } M = gets.to_i mentaikos = M.times.map { gets.split.map(&:to_i) } max_cnt = 1 ans = [] mentaikos.each.with_index(1) do |(x, y), idx| cnt = 0 persons.each do |a, b| next if a < x next if b > y cnt += 1 end if max_cnt < cnt max_cnt = cnt ans = [idx] elsif max_cnt == cnt ans << idx end end if ans.empty? puts 0 else puts ans end