import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  int n, m;
  readf("%s %s\n", &n, &m);
  auto x = readln.chomp.split.to!(long[]);
  sort(x); 
  if (m == 1) {
    x[0].writeln;
    return;
  }
  auto d = new long[](m-1);
  foreach (i; 0..m-1) {
    d[i] = x[i+1] - x[i];
  }
  sort(d);
  (d.sum - d[$-min(m,n-1)..$].sum).writeln;
}
