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

diffs = []
(0...m-1).each do |i|
  diffs << [sorted[i+1]-sorted[i], i]
end

diffs = diffs.sort_by{|t| -t[0]}.take(n-1)

result = 0
i = 0
diffs.each do |(d, j)|
  result += sorted[j] - sorted[i]
  i = j + 1
end
result += sorted[-1] - sorted[i]
puts result
