fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map(String::toInt)
    val x = readLine()!!.split(" ").map(String::toInt).sortedBy { it }
    val xd = (0 until m - 1).map { i -> Pair(i, x[i + 1] - x[i]) }
        .sortedByDescending { d -> d.second }
    val result = (n - 1 until m - 1).sumBy { i -> xd[i].second }
    println(result)
}
