loop do
  n = gets.to_i
  break if n.zero?
  ss = n.times.map { gets.split.map(&:to_i) }
  m = gets.to_i
  ss += m.times.map { gets.split.map(&:to_i) }
  cs = Array.new n + m, 0
  es = Array.new(n + m) { [] }
  rs = Array.new n + m, 0
  (n+m).times do |i|
    (n+m).times do |j|
      next if i == j
      if ss[i][0] < ss[j][0] && ss[i][1] < ss[j][1]
        cs[i] += 1
        es[j] << i
      end
    end
  end
  stack = []
  (n+m).times do |i|
    if cs[i].zero?
      stack << i
      rs[i] = 1
    end
  end
  until stack.empty?
    i = stack.pop
    es[i].each do |j|
      rs[j] = [rs[j], rs[i] + 1].max
      cs[j] -= 1
      stack << j if cs[j].zero?
    end
  end
  p rs.max
end