function main(input) {
    const args = input.split('\n');

    var NM = args[0].split(' ');
    var Spins = args[1].split(' ');

    var N = parseInt(NM[0]);
    var M = parseInt(NM[1]);

    for (var i = 0; i < M; i++) {
        // 数値に
        Spins[i] = parseInt(Spins[i]);
    }

    // 昇順ソート
    Spins.sort(function (a, b) { return a - b; });

    var diff = [M-1];

    // 差を求める
    for (var i = 0; i < M - 1; i++) {
        diff[i] = Math.abs(Spins[i] - Spins[i + 1]);
    }

    var ans = 0;

    if(M < N) {
        N = M;
    }

    var index = 0;
    var ans = 0;

    // 駒の数が差の配列の2倍より長い場合は小さいほうから選んでとる
    // そうでない場合には大きいほうから取り除く
    if(N < diff.length / 2) {
        for (var i = 0; i < N - 1; i++) {
            index = diff.indexOf(Math.max.apply(null, diff));
            diff[index] = 0;
        }

        for (var i = 0; i < M - 1; i++) {
            ans += diff[i];
        }

        // 答え
        console.log(ans);
    } else {
        var roop = diff.length - N + 1;
        var max = Math.max.apply(null, diff);

        for (var i = 0; i < roop; i++) {
            index = diff.indexOf(Math.min.apply(null, diff));
            ans += diff[index];
            diff[index] = max;
        }

        // 答え
        console.log(ans);
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));