N, M, *x = $stdin.read.split(/\s/).map(&:to_i)

x.sort!
distances = []
0.upto(x.size - 2) {|i|
  distances << x[i + 1] - x[i]
}

distances.sort!
distances.pop(N - 1)
puts distances.reduce(0) {|s, d| s + d }
