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

if N < M then
  d = Array.new(M-1)
  (0...M-1).each{|i| d[i] = X[i+1] - X[i]}

  puts d.sort[0, M-N].inject(:+)
else
  puts 0
end
