let input = readLine()!.split(separator: " ").map { Int($0)! }
let N = input[0]
let M = input[1]
let X = readLine()!.split(separator: " ").map { Int($0)! }.sorted()

if N >= X.count {
    print(0)
} else {
    var distances = [Int]()
    for i in stride(from: 0, to: X.count - 1, by: 1) {
        distances.append(abs(X[i] - X[i + 1]))
    }
    print(distances.sorted()[0 ..< distances.count - N + 1].reduce(0, +))
}
