N,K,*A=gets(p).split.map &:to_i a = [] A.sort.inject{|r,n| a << n-r n } p a.sort.take(N-K).sum