fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val a = readLine()!!.split(' ').map { it.toInt() }.sorted()
    val dists = (0 until m - 1).map { a[it + 1] - a[it] }.sortedDescending()
    val all = a.max()!! - a.min()!!
    println(all - dists.take(n - 1).sum())
}