#include <bits/stdc++.h>
using namespace std;
int a[500010];
double f[500010];
int s[500010];
int n, k;
bool check(double w) {
  for (int i = 2; i <= n; i++) {
    f[i] = f[i - 1];
    s[i] = s[i - 1];
    if (f[i - 2] + a[i] - a[i - 1] + w < f[i]) {
      f[i] = f[i - 2] + a[i] - a[i - 1] + w;
      s[i] = s[i - 2] + 1;
    }
  }
  return s[n] >= k;
}
int main() {
  scanf("%d%d", &k, &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  sort(a + 1, a + n + 1);
  double le = -1e9, ri = 0;
  for (int i = 1; i <= 100; i++) {
    double mid = (le + ri) * 0.5;
    if (check(mid))
      le = mid;
    else
      ri = mid;
  }
  printf("%.0lf", f[n] - le * k + 1e-8);
  return 0;
}
