N, M = gets.split(' ').map(&:to_i)
x = gets.split(' ').map(&:to_i)
x.sort!
y = []
(M - 1).times do |i|
  y.push(x[i + 1] - x[i])
end
y.sort!

ans = 0
if N < M
  ans = y[0..(M - N - 1)].inject(:+)
end

puts ans