ps =[1,2,3,4,5,6,7]
m = 3
ans =2
ps.each_slice(m) do |a|
  tmp = 1
  ans -= tmp if a.length == m
end

#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.inject(0){|sum,x| sum+x}
#  ps.each_slice(m) do |a|
#    tmp = a[-1]
#    ans -= tmp if a.length == m
#  end
#  puts ans
#end