class ProblemB
  def solve
    while true
      total = 0

      n, m = gets.split.map(&:to_i)
      return if n <= 0
      pn = gets.split.map(&:to_i).sort {|a, b| b <=> a }

      while pn.count > 0
        t = []
        m.times do |i|
          t.push pn.shift
          break if pn.count <= 0
        end
        t.pop if t.count == m
        t.each { |price| total += price }
      end

      total
    end
  end
end

thanksgiving = ProblemB.new
thanksgiving.solve