while true
    n, m = gets.chomp.split.map(&:to_i)
    break if [n, m] == [0, 0]
    arr = gets.chomp.split.map(&:to_i).sort
    c, amt = 0, 0
    until arr.empty?
        price = arr.pop
        amt += price if c % m != m - 1
        c += 1
    end
    puts amt
end
