import Foundation

class Scanner {
    static func readInt() -> Int {
        return Int(readLine()!)!
    }
    
    static func readIntArr() -> [Int] {
        return readLine()!.split(separator: " ").map { Int($0)! }
    }
    
    static func readM(_ n: Int) -> [[Int]] {
        var res = [[Int]]()
        for _ in 0..<n {
            res.append(readIntArr())
        }
        return res
    }
    
    static func readUknownIntMat() -> [[Int]] {
        var res = [[Int]]()
        while let line = readLine() {
            res.append(line.split(separator: " ").map { Int($0)! })
        }
        return res
    }
    
    static func readString() -> String {
        return readLine()!
    }
}

class Printer {
    static func printIntArray(_ arr: [Int]) {
        print(arr.map { String($0) }.joined(separator: " "))
    }
}


class Solution {
    
    func streamline(_ arr: [Int], _ n: Int) -> Int {
        guard n < arr.count else {
            return 0
        }
        /*
         n = 2, take first one
         */
        let arr = arr.sorted()
        var dist = [Int]()
        var res = 0
        for i in stride(from: 0, to: arr.count-1, by: 1) {
            dist.append(arr[i+1]-arr[i])
            res += dist.last!
        }
        dist.sort(by: { $0 > $1 })
        for i in stride(from: 0, to: n-1, by: 1) {
            res -= dist[i]
        }
        return res
    }
}


let nm = Scanner.readIntArr()
let arr = Scanner.readIntArr()
print(Solution().streamline(arr, nm[0]))
