#include <bits/stdc++.h>
struct chain {
  int val;
  chain *pr, *nx;
  chain() {}
  chain(int a, chain* b, chain* c) : val(a), pr(b), nx(c) {}
} a[500000];
std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >,
                    std::greater<std::pair<int, int> > >
    q;
int tmp[500000];
int main() {
  int i, n, k, x, lst;
  scanf("%d%d", &k, &n);
  for (i = 0; i < n; i++) scanf("%d", tmp + i);
  std::sort(tmp, tmp + n), lst = *tmp;
  for (i = 1; i < n; i++)
    x = tmp[i], a[i] = chain(x - lst, a + i - 1, a + i + 1),
    q.push(std::pair<int, int>(x - lst, i)), lst = x;
  a[1].pr = a[n - 1].nx = a;
  int sum = 0;
  chain* s;
  while (true) {
    do s = a + q.top().second, q.pop();
    while (s->val == -1);
    sum += s->val;
    if (!--k) break;
    if (s->nx == a) {
      s->pr->val = -1;
      s->pr->pr->nx = a;
      continue;
    }
    if (s->pr == a) {
      s->nx->val = -1;
      s->nx->nx->pr = a;
      continue;
    }
    s->pr->pr->nx = s;
    s->nx->nx->pr = s;
    s->val = s->pr->val + s->nx->val - s->val;
    s->pr->val = s->nx->val = -1;
    s->pr = s->pr->pr;
    s->nx = s->nx->nx;
    q.push(std::pair<int, int>(s->val, s - a));
  }
  printf("%d\n", sum);
  return 0;
}
