fun main(args: Array<String>) = println(run {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val x = readLine()!!.split(" ").map { it.toInt() }.sorted()
    val d = IntArray(m-1) { x[it+1] - x[it] }.sorted()
    if(m>=n) d.take(m-n).sum() else 0
})