N, K = gets.split.map(&:to_i) A = gets.split.map(&:to_i).sort ans = A.each_index .each_cons(2) .map{|i,j| [i, j, A[i] - A[j]] } .sort_by(&:last) .take(K - 1) .sort_by(&:first) .map{|v| v[0,2] } .flatten .tap{|sec| sec.unshift(0); sec.push(N - 1)} .each_slice(2) .map{|l,r| A[r] - A[l] } .sum puts ans