fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val X = listOfInt().sorted()
    if (N >= M) { println(0); return }
    val L = Array(M - 1) { X[it + 1] - X[it] }.sortedArrayDescending().toList()
    val lSum = L.subList(0, N - 1).sum()
    val ans = (X.last() - X.first()) - lSum
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)