'use strict';

function main(input) {
  const lines = input.split('\n');
  const first = lines[0].split(' ').map(Number);
  const N = first[0];
  const M = first[1];
    // コマ数が点よりも多い場合
  if (M <= N) {
      console.log(0)
    return ;
  }
  const x = lines[1]
    .split(' ')
    .map(Number)
    .sort((a, b) => a - b);

    // 点ごとの差を取る
  const diffs = [];
  for (let i = 1; i < x.length; i++) {
    diffs.push(x[i] - x[i - 1]);
  }
    // 昇順
  diffs.sort((a, b) => a - b);

    // 
  let sum = diffs.slice(0, M - N).reduce((a, c) => a + c);
  console.log(sum);
}

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