fun main(args : Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
    val X = readLine()!!.split(" ").map { it.toLong() }.toLongArray()
    X.sort()
    if ( M == 1) {
        println(0)
        return
    }



    val diffs = LongArray(M -1)
    for (i in 0 until M - 1) {
        diffs[i] = X[i+1] - X[i]
    }
    diffs.sortDescending()

    var sum = diffs.sum()
    for (i in 0 until Math.min((N - 1), M - 1)) {
        sum -= diffs[i]
    }

    println(sum)
}