import io.{StdIn => in}

object Main extends App {
  val Array(n, m) = in.readLine.split(" ").map(_.toInt)
  val x = in.readLine.split(" ").map(_.toInt).sorted
  val ans = x.tail.scanLeft(0, x.head)((acc,i) => {
    (i - acc._2, i)
  }).tail.map(_._1).sorted.take(m-n).sum
  println(ans)
}
