function main(input) {
  var n = input[0].split(" ")[0]-0;
  var m = input[0].split(" ")[1]-0;
  var x = input[1].split(" ").sort((a,b)=>a-b);

  var lens = [];
  for(var i=1;i<m;i++){
    lens.push(Math.abs(x[i]-x[i-1]));
  }
  lens.sort((a,b)=>a-b);
  var ans = 0;
  for(var i=0;i<=m-1-n;i++){
    ans += lens[i];
  }
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))
