import std.stdio;
import std.string;
import std.conv;
//import std.typecons;
import std.algorithm;
import std.array;

void main() {
	auto data = split(readln());
	auto N = data[0].to!int(), M = data[1].to!int();
	int[] X = split(readln()).map!(x => to!int(x)).array.sort().array;
	
	if (N >= M) { writeln("0"); return; }
	
	int[] d;
	foreach (i; 0 .. M-1) { d ~= X[i+1] - X[i]; }
	d = sort(d).array;
	writeln( reduce!"a+b"(d[0 .. M-N]) );
	
}
