loop do
    w, d = gets.split.map(&:to_i)
    break if w == 0 && d == 0
    c = gets.split.map(&:to_i)
    r = gets.split.map(&:to_i)
    max = [c.max, r.max].max
    sum = 0
    1.upto(max) do |i|
        count = [c.count(i), r.count(i)].max
        sum += count * i
    end
    puts sum
end