#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  register long long x = 0, f = 1;
  register char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  return x * f;
}
void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
void writeln(long long x) {
  write(x);
  puts("");
}
const int inf = 0x3fffffff;
const int maxn = 500005;
int n, k, a[maxn], pre[maxn], nxt[maxn], ans;
int main() {
  k = read(), n = read();
  for (register int i = (1); i <= int(n); ++i) a[i] = read();
  sort(a + 1, a + 1 + n);
  priority_queue<pair<int, int> > Q;
  for (register int i = (1); i < int(n); ++i)
    a[i] = a[i + 1] - a[i], Q.push(pair<int, int>(-a[i], i));
  for (register int i = (0); i <= int(n); ++i) pre[i] = i - 1, nxt[i] = i + 1;
  a[0] = a[n] = inf;
  pre[0] = nxt[n - 1] = ans = 0;
  while (k--) {
    while (!Q.empty() && (a[Q.top().second] != -Q.top().first)) Q.pop();
    if (Q.empty()) 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], inf) : inf;
    Q.push(pair<int, int>(-a[x], x));
    a[l] = a[r] = inf;
    nxt[pre[x] = pre[l]] = x;
    pre[nxt[x] = nxt[r]] = x;
  }
  writeln(ans);
  return 0;
}
