def solve
  while true
    n, m = gets.split.map(&:to_i)
    break if n <= 0

    total = 0

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

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

solve