N,M = gets.chomp.split.map(&:to_i)
Xs = gets.chomp.split.map(&:to_i).sort
dist = []
x_pre = Xs[0]
Xs.each do |x|
  dist.push((x_pre - x).abs)
  x_pre = x
end
dist.shift
if N >= M
  ans = 0
else
  dist.sort!.reverse!
  (N-1).times{dist.shift}
  ans = dist.inject(:+)
end
puts ans
