n = gets.chomp.to_i
x = gets.chomp.split(' ').map {|v| v.to_i}
x.sort!
dist = Array.new(x.length - 1)

dist.length.times do |i|
  dist[i] = x[i + 1] - x[i]
end

dist.sort!.reverse!
dist.slice!(0, n - 1)
puts "#{dist.sum}"

