#include <bits/stdc++.h>
using namespace std;
map<long long, long long> isi;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long z, x;
  cin >> z >> x;
  long long d[x];
  for (long long q = 0; q < x; q++) {
    cin >> d[q];
  }
  sort(d, d + x);
  priority_queue<pair<long long, pair<long long, long long> > > asd;
  long long c;
  for (long long q = 1; q < x; q++) {
    c = d[q] - d[q - 1];
    asd.push(make_pair(-c, make_pair(-d[q], -d[q - 1])));
  }
  long long total = 0, f, total1 = 0;
  long long wtf = z, wtf2 = z;
  long long itung = 0, itung1 = 0;
  long long totaldata = x;
  if (!asd.empty()) {
    while (1) {
      if (isi[asd.top().second.first] == 0 &&
          isi[asd.top().second.second] == 0) {
        total = total + (asd.top().first * (-1));
        isi[asd.top().second.first]++;
        isi[asd.top().second.second]++;
        totaldata = totaldata - 2;
        z--;
      }
      asd.pop();
      itung++;
      if (z == 0 || totaldata < 2 || asd.empty()) break;
    }
  }
  cout << total << endl;
}
