fun main(args:Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val posList = readLine()!!.split(" ").map { it.toInt() }.sorted()
    if(n >= m) {
        println(0)
        return
    }
    val areaList = (1..posList.lastIndex).map { posList[it] - posList[it-1] }.sorted()
    val ans = areaList.take(m - n).sum()?:0
    println(ans)
}
