while (w, d = gets.split.map(&:to_i)).inject(:+) != 0 do
  front = Array.new
  side = Array.new
  gets.split.map(&:to_i).each do |i|
    front[i] = 0 if !front[i]
    front[i] += 1
  end
  gets.split.map(&:to_i).each do |i|
    side[i] = 0 if !side[i]
    side[i] += 1
  end
  front.collect!{|v| v ? v : 0}
  side.collect!{|v| v ? v : 0}
  answer = 0
  front.size.times do |i|
    answer += [front[i], side[i]].max * i
  end
  p answer
end