import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, long M, long[] X) {
    auto goals = X.sort();
    return goals.back - goals.front - iota(M - 1)
        .map!(i => goals[i + 1] - goals[i])
        .array
        .sort!"a > b"
        .take(N - 1)
        .sum;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long M;
    M = input.front.to!long;
    input.popFront;

    long[] X = new long[](cast(size_t) (M));
    foreach (i; 0 .. cast(size_t) (M)) {
        X[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(N, M, X);
    else
        solve(N, M, X).writeln;
}
