### main

while true
  n, m = gets.strip.split(' ').map{|s| s.to_i}
  break if n == 0 && m == 0

  ps = gets.strip.split(' ').map{|s| s.to_i}.sort{|a, b| b <=> a}

  sum = (0...n).inject(0){|s, i| s + (((i + 1) % m == 0) ? 0 : ps[i])}
  puts sum
end