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

if m == 1
  puts 0
  exit
end
if n == 1
  puts xs[-1] - xs[0]
  exit
end

distances = []
(xs.size-1).times do |i|
  distances.push xs[i+1] - xs[i]
end
puts distances.sort[0, distances.size-(n-1)].inject(:+)
