n,m = gets.chomp.split(' ').map(&:to_i)
if n >= m
  puts 0 
else
  places = gets.chomp.split(' ').map(&:to_i).sort
  distances = (1..m - 1).map{|i| places[i] - places[i - 1]}.sort
  puts distances[0..n].inject(:+)
end