import std.stdio, std.conv, std.string, std.range, std.typecons, std.format;
import std.algorithm.searching, std.algorithm.sorting, std.algorithm.iteration, std.algorithm.mutation;

void main()
{
    int[] input = readln().split.to!(int[]);
    int N = input[0];
    int M = input[1];
    int[] targets = readln().split.to!(int[]);
    if(N>=M)
    {
        writeln(0);
        return;
    }

    int[] saList;
    saList.length = targets.length-1;
    auto sortedTarget = targets.sort();
    for(int i = 0;i < sortedTarget.length-1;i++)
    {
        saList[i] = sortedTarget[i+1] - sortedTarget[i];
    }
    writeln(saList.sort()[0..$-(N-1)].sum());
}
