N,M = readline.chomp.split.map(&:to_i)
if N >= M
  puts '0'
  exit
end
xs = readline.chomp.split.map(&:to_i).sort
ds = (xs.size-1).times.each.map {|i| xs[i+1]-xs[i] }.sort
puts ds[0..(M-1-(N-1)-1)].inject(:+)
