#include <bits/stdc++.h>
using namespace std;
const int N = 500050;
long long input() {
  long long f = 1, s = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    s = s * 10 + c - '0';
    c = getchar();
  }
  return s * f;
}
long long n, m, a[N], ans;
int pre[N], nxt[N];
bool p[N];
priority_queue<pair<long long, int> > q;
void del(int x) {
  p[x] = 1;
  pre[nxt[x]] = pre[x];
  nxt[pre[x]] = nxt[x];
  pre[x] = nxt[x] = 0;
}
void work() {
  while (p[q.top().second]) q.pop();
  int x = q.top().second;
  ans += a[x];
  q.pop();
  a[x] = a[pre[x]] + a[nxt[x]] - a[x];
  del(pre[x]);
  del(nxt[x]);
  q.push(make_pair(-a[x], x));
}
int main() {
  m = input();
  n = input();
  for (int i = 1; i <= n; ++i) a[i] = input();
  sort(a + 1, a + n + 1);
  for (int i = 1; i < n; ++i)
    a[i] = (a[i + 1] - a[i]), pre[i] = i - 1, nxt[i] = i + 1;
  nxt[n - 1] = 0;
  for (int i = 1; i < n; ++i) q.push(make_pair(-a[i], i));
  long long res = 0;
  for (; m--;) {
    work();
  }
  cout << ans << endl;
  return 0;
}
