fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map(String::toInt)
    val dl = mutableListOf<Int>()
    readLine()!!.split(" ").map(String::toInt).sorted().reduce { a, b -> dl.add(b - a); b }
    dl.sort()
    print(if (m > n) dl.take(m - n).sum() else 0)
}