n,m=gets.split.map{|e| e.to_i} x=gets.split.map{|e| e.to_i}.sort y=[] if n==1 puts 0 else (0..x.size-2).each{|i| y<<(x[i+1]-x[i]) } y.sort! ans=0 (n-m).times{|i| ans+=y[i] } puts ans end