object Main extends App {
    val Array(n, m) = io.StdIn.readLine.split(" ").map(_.toInt)
    val xs = io.StdIn.readLine.split(" ").map(_.toInt)

    if (m <= n) println(0)
    else {
        val sorted = xs.sorted
        val ls = sorted.sliding(2).map(range => range.last - range.head).toArray.sorted.reverse
        val not_moved_section = ls.take(n-1).sum
        val all_section = sorted.last - sorted.head
        println(all_section-not_moved_section)
    }
}