N, M = gets.chomp.split.map(&:to_i)
X = gets.chomp.split.map(&:to_i).sort

ans = 0
if M > N
  diffs = (1...X.length).to_a.map{|i| X[i] - X[i - 1]}.sort
  ans = diffs[0...(M - N)].inject(&:+)
end
puts ans