object Main {
    def main(args: Array[String]) {
        val sc = new java.util.Scanner(System.in)
        val n = sc.nextInt
        val m = sc.nextInt
        var arr = new Array[Int](m)
        var arr2 = new Array[Int](m - 1)
        for (i <- 0 to m - 1) {
            val k = sc.nextInt
            arr(i) = k
        }
        arr.sorted

        for (i <- 1 to m - 1) {
            arr2(i - 1) = abs(arr(i) - arr(i - 1))
        }

        arr2.sorted

        val k = m - n
        var ans = 0
        for (i <- 0 to k - 1) {
            ans += arr2(i)
        }

        println(ans)
    }

    def printArray(arr: Array[Int]) {
        for (i <- 0 to arr.length - 1) {
            println(arr(i))
        }
    }

    def swap(arr: Array[Int], i: Int, j: Int) {
        val tmp = arr(i)
        arr(i) = arr(j)
        arr(j) = tmp
    }

    def abs(a: Int): Int = if (a > 0) a else -a

    def sort(arr: Array[Int]) {
        for (i <- 0 to arr.length - 1) {
            var min = i
            for (j <- i to arr.length - 1) {
                if (arr(j) < arr(min)) {
                    min = j
                }
            }
            swap(arr, i, min)
        }
    }
}