object Main{
  def main(args: Array[String]){
      	val ct = io.StdIn.readLine.split(" ").map(_ .toInt)
    	val dots = io.StdIn.readLine.split(" ").map(_ .toInt).sorted.toList
       val diffs= dots.zip(dots.tail).map{ t => t._2 - t._1 }.sorted
    	val dist = dots(ct(1)-1) - dots(0)
        print((dist- diffs.takeRight(ct(0)-1).sum).toString)
   
  }
}