log = console.log;

var stdin = require("fs").readFileSync("/dev/stdin", "UTF-8");
var lines = stdin.split("\n");
var N = lines[0].split(" ")[0];
var M = lines[0].split(" ")[1];
var XS = lines[1]
  .split(" ")
  .map(v => ~~v)
  .sort((a, b) => a - b);

if (N >= M) {
  log(0);
} else {
  LS = [];
  for (var i = 0; i < XS.length - 1; i++) {
    var L = XS[i + 1] - XS[i];
    LS.push(L);
  }

  LS.sort((a, b) => a - b);
  sum = LS.slice(0, M - N).reduce((a, c) => a + c);

  log(sum);
}