import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    long n, m;
    scan(n, m);
    auto x = aryread();
    // writeln(n);
    // writeln(x);
    // x.sort().writeln();
    x.sort();
    // writeln(x);
    if (x.length == 1 && m == 1)
    {
        writeln(0);
        return;
    }
    auto tmp = new long[](m - 1);

    foreach (i; 0 .. m - 1)
    {
        tmp[i] = abs(x[i + 1] - x[i]);
    }
    // writeln("差", tmp); //i番目はx[i]とx[i+1]の絶対値
    tmp.sort();
    // writeln("差をsort", tmp);
    long ans;
    // foreach (i; 0 .. (tmp.length) - n + 1)
    // {
    //     // writeln(tmp[i]);
    //     ans += tmp[i];
    // }
    // writeln(ans);
    sum(tmp[0 .. ($ - (n - 1))]).writeln();
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}
