require 'enumerator'
loop do
  n,m = gets.split.map(&:to_i)
  break if(n|m)==0
  ps = gets.split.map(&:to_i)
  ps.sort!{|a,b|b-a}
  ans = ps.reduce(:+)
  ps.each_slice(m) do |a|
    ans -= a.pop if a.size ==m
  end
  p ans
end