import scala.io.StdIn

object Main{

  def main(args: Array[String]): Unit = {
    val Array(n, m) = StdIn.readLine().split(' ').map(_.toInt)
    val xs = StdIn.readLine().split(' ').map(_.toInt).toVector.sorted
    println(solve(n, m, xs))
  }

  def solve(n: Int, m: Int, xs: Vector[Int]): Int = {
    if (m <= n) {
      0
    } else {
      val dxs = xs.sliding(2).map(xx => xx(1) - xx(0)).toVector.sorted
      dxs.dropRight(n - 1).sum
    }
  }

}
