#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
int k, n, m;
int a[N];
int s[N];
double f[N];
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  double l = -1e9, r = 0;
  while (r - l > 1e-6) {
    double Mid = (l + r) / 2;
    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] + Mid < f[i])
        f[i] = f[i - 2] + a[i] - a[i - 1] + Mid, s[i] = s[i - 2] + 1;
    }
    if (s[n] == m) {
      printf("%I64d\n", (long long)(f[n] - Mid * m + 1e-3));
      return 0;
    }
    if (s[n] > m)
      l = Mid;
    else
      r = Mid;
  }
  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] + l < f[i])
      f[i] = f[i - 2] + a[i] - a[i - 1] + l, s[i] = s[i - 2] + 1;
  }
  printf("%I64d\n", (long long)(f[n] - l * m + 1e-3));
  return 0;
}
