#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const long double eps = 1e-8;
long long read() {
  char ch = getchar();
  long long x = 0;
  int op = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') op = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
  return x * op;
}
void write(long long a) {
  if (a < 0) putchar('-'), a = -a;
  if (a >= 10) write(a / 10);
  putchar(a % 10 + '0');
}
long long ksm(long long x, long long p) {
  long long ret = 1;
  for (; p; p >>= 1, x = x * x)
    if (p & 1) ret = ret * x;
  return ret;
}
int n, k, a[500005], pre[500005], nxt[500005];
long long ans;
int main() {
  k = read(), n = read();
  for (int i = (1); i <= (n); i++) a[i] = read();
  sort(a + 1, a + 1 + n);
  priority_queue<pair<int, int> > q;
  for (int i = (1); i <= (n - 1); i++)
    a[i] = a[i + 1] - a[i], q.push(pair<int, int>(-a[i], i));
  for (int i = (0); i <= (n); i++) pre[i] = i - 1, nxt[i] = i + 1;
  a[0] = a[n] = 1000000000;
  pre[0] = nxt[n - 1] = ans = 0;
  while (k) {
    while (q.size() && a[q.top().second] != -q.top().first) q.pop();
    if (!q.size()) break;
    int x = q.top().second;
    ans += a[x];
    q.pop();
    int l = pre[x], r = nxt[x];
    a[x] = (l && r) ? min(a[l] + a[r] - a[x], 1000000000) : 1000000000;
    q.push(pair<int, int>(-a[x], x));
    a[l] = a[r] = 1000000000;
    nxt[pre[x] = pre[l]] = x;
    pre[nxt[x] = nxt[r]] = x;
    k--;
  }
  cout << ans << endl;
  return 0;
}
