#include <bits/stdc++.h>
using namespace std;
const int MAX = 5e5 + 1;
int n, m;
long long TOT;
int joking[MAX], L[MAX], R[MAX], tax[MAX], p[MAX];
void del(int x) {
  while ((x << 1) <= n) {
    int f;
    if ((x << 1) == n || joking[tax[(x << 1)]] < joking[tax[(x << 1) + 1]])
      f = (x << 1);
    else
      f = (x << 1) + 1;
    if (joking[tax[x]] < joking[tax[f]]) return;
    swap(tax[x], tax[f]);
    swap(p[tax[x]], p[tax[f]]);
    x = f;
  }
}
int read() {
  int x = 0;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    ;
  for (; isdigit(ch); x = x * 10 + ch - 48, ch = getchar())
    ;
  return x;
}
int main() {
  m = read(), n = read();
  for (int i = 1; i <= n; i++) joking[i] = read();
  sort(joking + 1, joking + 1 + n);
  for (int i = 1; i <= n; ++i) joking[i] = joking[i + 1] - joking[i];
  --n;
  for (int i = 1; i <= n; i++) {
    L[i] = (i == 1) ? 1 : i - 1, R[i] = (i == n) ? n : i + 1, tax[i] = p[i] = i;
    int tt = i;
    while (tt > 1 && joking[tax[(tt >> 1)]] > joking[tax[tt]]) {
      swap(tax[(tt >> 1)], tax[tt]);
      swap(p[tax[(tt >> 1)]], p[tax[tt]]);
      tt >>= 1;
    }
  }
  for (int i = 1; i <= m; i++) {
    int ttt = tax[1];
    TOT += joking[ttt];
    joking[ttt] = joking[L[ttt]] + joking[R[ttt]] - joking[ttt];
    joking[L[ttt]] = 1e9;
    del(p[L[ttt]]);
    joking[R[ttt]] = 1e9;
    del(p[R[ttt]]);
    del(1);
    L[ttt] = L[L[ttt]];
    R[ttt] = R[R[ttt]];
    R[L[ttt]] = ttt;
    L[R[ttt]] = ttt;
  }
  cout << TOT;
  return 0;
}
