"use strict";
function main(input) {
  const inputs = input.split("\n").filter(x => x !== "");

  const N = inputs[0].split(" ").map(Number)[0];
  const X = inputs[1].split(" ").map(Number);

  const sX = X.sort((a,b) => a-b);
  // console.log(sX);
  const diff = [];

  for (let i =0; i<sX.length-1; i++) {
    diff[i] = sX[i+1] -sX[i];
  }

  // console.log(diff)

  const sDiff = diff.sort((a,b) => a-b);

  console.log(sDiff.reduce((acc,cur) => cur + acc, 0) - sDiff.slice(sDiff.length - (N -1)).reduce((acc,cur) => cur + acc, 0))
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
