#include <bits/stdc++.h>
using namespace std;
const int maxn = 5 * 1e5 + 5;
long long a[maxn];
struct node {
  long long u, v, cost;
  node(long long u, long long v, long long cost) : u(u), v(v), cost(cost) {}
  friend bool operator<(node N1, node N2) { return N1.cost > N2.cost; }
};
int main() {
  int k, n;
  scanf("%d%d", &k, &n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  priority_queue<node> pq;
  while (!pq.empty()) pq.pop();
  for (int i = 1; i < n; i++) pq.push(node(i - 1, i, a[i] - a[i - 1]));
  set<int> all;
  all.clear();
  long long sum = 0;
  while (!pq.empty()) {
    if (!k) break;
    node p = pq.top();
    pq.pop();
    if (all.find(p.u) == all.end() && all.find(p.v) == all.end()) {
      all.insert(p.u);
      all.insert(p.v);
      sum += p.cost;
      k--;
    }
  }
  if (!k)
    cout << sum << "\n";
  else {
    long long sum = 0;
    for (int i = 1; i < n; i += 2) sum += a[i] - a[i - 1];
    cout << sum << "\n";
  }
  return 0;
}
