n, m = gets.chomp.split.map(&:to_i)
x = gets.chomp.split.map(&:to_i)
if m <= n
  puts "0"
else
  x.sort!
  d = []
  x.each_cons(2) do |i, j|
    d << j - i
  end
  d.sort!
  puts d[0..(m - n - 1)].inject(:+) || 0
end