fun main(args: Array<String>) {
    val (N, M) = readInputLine().split(" ").map{it.toInt()}
    
    if (N >= M) {
        println(0)
        return
    }
    
    val Xs = readInputLine().split(" ").map{it.toInt()}.toIntArray()
    Xs.sort()
    
    val L = mutableListOf<Int>()
    
    for (i in 1 until M) {
        L.add(Xs[i] - Xs[i - 1])
    }
    
    L.sortDescending()

    println(Xs[M - 1] - Xs[0] - L.take(N - 1).sum())
}

fun readInputLine(): String {
    return readLine()!!
}
