loop do
  w, d = gets.chomp.split.map(&:to_i)
  break if w.zero? && d.zero?

  widths  = Array.new(21, 0)
  heights = Array.new(21, 0)

  gets.split.map(&:to_i).each do |i|
    widths[i] += 1
  end
  gets.split.map(&:to_i).each do |i|
    heights[i] += 1
  end

  answer = 0
  0.upto(20).each do |i|
    answer += [widths[i], heights[i]].max * i
  end

  puts answer
end