n,m = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i).sort
abs = []
arr.each_with_index do |x,i|
  break if arr[i+1] == nil
  a = x - arr[i+1]
  abs << a.abs
end

if n >= m
  puts 0
else
  p abs.sort.reverse[n-1..-1].inject(:+)
end