import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto A = readln.split.map!(to!long).array;
    A.sort();

    if (N >= M) {
        writeln(0);
        return;
    }

    auto B = new Tuple!(int, long)[](M-1);
    foreach (i; 0..M-1) B[i] = tuple(i, A[i+1] - A[i]);
    B.sort!"a[1] > b[1]";

    auto C = new bool[](M+1);
    foreach (i; 0..N-1) C[B[i][0]+1] = true;

    long ans = 0;
    long tmp = 0;
    long start = 0;

    foreach (i; 1..M) {
        if (C[i]) {
            ans += A[i-1] - A[start];
            start = i;
        } else {
        }
    }

    ans += A.back - A[start];

    ans.writeln;
}
