
object Main extends App {
  import scala.io.StdIn._

  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val positions = readLine.trim.split(' ').map(_.toLong).sorted
  val distances = positions.indices.tail.map(i ⇒ positions(i) - positions(i - 1)).toArray.sorted(Ordering.Long.reverse)
  if (n >= m){
    println(0)
  }else {
    println(distances.drop(n - 1).sum)
  }
}