
fun main(args: Array<String>) {
    val nm = readLine()!!.split(" ").map { it.toInt() }
    val n = nm[0]
    val m = nm[1]

    if (n >= m) {
        println(0)
        return
    }

    val x = readLine()!!.split(" ").map { it.toInt() }.sorted()
    val l = mutableListOf<Int>()

    for (i in 1..(x.size - 1)) {
        l.add(x[i] - x[i - 1])
    }

    val tmp = l.sorted().reversed().subList(0, n - 1).sum()
    val range = x[x.size - 1] - x[0]
    println(range - tmp)
}
