#include <bits/stdc++.h>
using namespace std;
const int maxn = 500005;
struct node {
  int l, r;
  long long val;
  bool operator<(const node &a) const { return val > a.val; }
} now;
priority_queue<node> Q;
int t[maxn], a[maxn], f[maxn], n, K, cnt;
long long ans, sum[maxn], tot;
int main() {
  scanf("%d%d", &K, &n);
  for (int i = (1); i <= int(n); i++) scanf("%d", &t[i]);
  sort(t + 1, t + n + 1);
  n--;
  for (int i = (1); i <= int(n); i++) {
    a[i] = t[i + 1] - t[i];
    sum[i] = sum[i - 1] + a[i];
    Q.push((node){i, i, a[i]});
  }
  while (K--) {
    int fff = 0;
    while (Q.size()) {
      now = Q.top();
      Q.pop();
      cnt = 0;
      for (int i = (now.l); i <= int(now.r); i++) cnt += f[i];
      if (cnt == (now.r - now.l) / 2 && !f[now.l - 1] && !f[now.r + 1]) break;
      if (Q.empty()) fff = 1;
    }
    if (fff) break;
    ans += now.val;
    tot = 0;
    for (int i = (0); i <= int(now.r - now.l); i++) {
      f[now.l + i] = (i & 1) ^ 1;
      if (f[now.l + i]) tot += a[now.l + i];
    }
    while (3 <= now.l && f[now.l - 2]) {
      now.l -= 2;
      tot += a[now.l];
    }
    while (now.r <= n - 2 && f[now.r + 2]) {
      now.r += 2;
      tot += a[now.r];
    }
    if (2 <= now.l && now.r <= n - 1)
      Q.push(
          (node){now.l - 1, now.r + 1, sum[now.r + 1] - sum[now.l - 2] - tot});
    if (3 <= now.l)
      Q.push((node){now.l - 2, now.r, sum[now.r] - sum[now.l - 3] - tot});
    if (now.r <= n - 2)
      Q.push((node){now.l, now.r + 2, sum[now.r + 2] - sum[now.l - 1] - tot});
  }
  printf("%I64d\n", ans);
  return 0;
}
