# frozen_string_literal: true
n, m = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
if n >= m
  puts 0
  exit 0
end
sorted_x = x.sort
diff_x = {}
(0..m-2).each do |i|
  diff_x[i+1] = sorted_x[i+1] - sorted_x[i]
end
sorted_diff = diff_x.sort { |a,b| a[1] <=> b[1] }.reverse
pos = []
pos[0] = 0
pos[n] = m
(1..n-1).each do |i|
  pos[i] = sorted_diff[i-1][0]
end
puts (0..n-1).reduce(0) { |sum, i| sum += sorted_x[pos[i+1]-1] - sorted_x[pos[i]] }
