void main() {
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], m = tmp[1];
    int[] x = readln.split.to!(int[]);
    x.sort!"a < b";
    int[] diff = new int[m-1];
    foreach (i; 0 .. m-1) {
        diff[i] = x[i+1] - x[i];
    }
    diff.sort!"a < b";
    writeln(n < m ? diff[0..m-n].sum : 0);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;