loop do
  begin
    n, m = gets.chomp.split.map(&:to_i)
    break if n == 0 && m == 0
    vegitables = gets.chomp.split.map(&:to_i).sort.reverse

    vegitables.each.with_index(1) do |v, i|
      if i % m == 0
        vegitables[i - 1] = 0
      end
    end

    p vegitables.inject(:+)
  rescue
    next
  end
end