#include <bits/stdc++.h>
using namespace std;
void getint(int &v) {
  char ch, fu = 0;
  for (ch = '*'; (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
    ;
  if (ch == '-') fu = 1, ch = getchar();
  for (v = 0; ch >= '0' && ch <= '9'; ch = getchar()) v = v * 10 + ch - '0';
  if (fu) v = -v;
}
const int INF = 1e9 + 10;
int n, k, p, L, R, a[500010], t[500010], l[500010], r[500010], ans;
bool v[500010];
pair<int, pair<int, int> > x;
priority_queue<pair<int, pair<int, int> > > Q;
int main() {
  cin >> k >> n;
  for (int i = 1; i <= n; i++) getint(a[i]);
  sort(a + 1, a + n + 1);
  for (int i = n; i >= 2; i--) a[i] = a[i] - a[i - 1];
  a[1] = a[++n] = INF;
  for (int i = 1; i <= n; i++)
    l[i] = i - 1, r[i] = i + 1, t[i] = 1,
    Q.push(make_pair(-a[i], make_pair(i, 1)));
  while (k--) {
    for (x = Q.top(); v[x.second.first] || x.second.second != t[x.second.first];
         Q.pop(), x = Q.top())
      ;
    p = x.second.first;
    L = l[p];
    R = r[p];
    r[L] = r[R];
    l[r[R]] = L;
    ans -= x.first;
    v[R] = v[p] = 1;
    a[L] += a[R] - a[p];
    Q.push(make_pair(-a[L], make_pair(L, ++t[L])));
  }
  printf("%d\n", ans);
  return 0;
}
