#include <bits/stdc++.h>
using namespace std;
int n, k, ti[500005], siz[500005];
double f[500005], ans = 0;
bool check(double mid) {
  memset(f, 0, sizeof(f));
  memset(siz, 0, sizeof(siz));
  for (int i = 2; i <= n; i++) {
    f[i] = f[i - 1];
    siz[i] = siz[i - 1];
    if (f[i] > f[i - 2] + ti[i] - ti[i - 1] + mid) {
      f[i] = f[i - 2] + ti[i] - ti[i - 1] + mid;
      siz[i] = siz[i - 2] + 1;
    }
  }
  ans = f[n] - k * mid + 1e-7;
  return siz[n] >= k;
}
int main() {
  scanf("%d%d", &k, &n);
  for (int i = 1; i <= n; i++) scanf("%d", ti + i);
  sort(ti + 1, ti + n + 1);
  double l = -1000000, r = 1000000;
  while (r - l >= 1e-7) {
    double mid = (l + r) / 2;
    if (check(mid))
      l = mid;
    else
      r = mid;
  }
  printf("%.0lf", ans);
}
