import java.util.*

fun main(vararg args: String) {
    val scanner = Scanner(System.`in`)
    val pieces = scanner.nextInt()
    val numOfObjectives = scanner.nextInt()
    val coordinateList = mutableListOf<Int>()
    val distances = mutableListOf<Int>()
    for (i in 0 until numOfObjectives) {
        coordinateList.add(scanner.nextInt())
    }
    coordinateList.sort()

    if (pieces >= numOfObjectives) {
        println(0)
        return
    }

    for ( i in 0 until coordinateList.size - 1) {
        distances.add(coordinateList[i + 1] - coordinateList[i])
    }
    distances.sort()

    val answer = distances.subList(0, distances.size - (pieces - 1)).sum()
    println(answer)
}