n, m = gets.split.map(&:to_i)

xs = gets.split.map(&:to_i)
xs.sort!

if m == 1
  puts 0
elsif m == 2
  if n == 1
    puts xs[1] - xs[0]
  else
    puts 0
  end
else
  diff = []
  for i in 0..(m-2) do
    diff << xs[i+1] - xs[i]
  end

  diff.sort! { |a, b| b<=>a }

  diff.slice!(0, n - 1)
  puts diff.inject(:+).to_i
end