def pack v, m
  array = Array.new
  while v.size > 0 do
    array << v.take(m)
    v = v.drop(m)
  end
  array
end

def getPrice v, m
  packs = pack v, m
  sum = 0
  packs.each do |p|
    p.pop if p.size == m
    sum += p.inject(:+)
  end
  sum
end

loop do
  n,m = $stdin.gets.chomp.split(" ").map(&:to_i)
  break if n|m == 0
  vegetable = $stdin.gets.chomp.split(" ").map(&:to_i).sort!{|p,q| q <=> p}
  puts(getPrice(vegetable, m))
end