#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f;
int n, k;
int a[500005], d[500005];
int f[3][5005];
inline int read() {
  register int x = 0, w = 1;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * w;
}
int main() {
  k = read(), n = read();
  for (register int i = 1; i <= n; ++i) a[i] = read();
  stable_sort(a + 1, a + 1 + n);
  for (register int i = 1; i < n; ++i) d[i] = a[i + 1] - a[i];
  memset(f, inf, sizeof(f));
  f[1][1] = d[1];
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j <= min(k, (i + 1) >> 1); ++j) {
      f[i % 3][j] = min(f[(i - 1) % 3][j], f[(i - 2) % 3][j - 1] + d[i]);
    }
  }
  printf("%d\n", f[(n - 1) % 3][k]);
}
