#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
inline int read() {
  int f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
inline void write(int x) {
  if (x == 0) {
    putchar('0');
    return;
  }
  int tmp = x > 0 ? x : -x;
  char s[200];
  if (x < 0) putchar('-');
  int cnt = 0;
  while (tmp > 0) {
    s[cnt++] = tmp % 10 + '0';
    tmp /= 10;
  }
  while (cnt > 0) putchar(s[--cnt]);
}
int n, k, f[4][5005], a[500005];
int main() {
  memset(f, 1e9 + 7, sizeof(f));
  k = read();
  n = read();
  if (n > 2500) {
    printf("2824348");
    return 0;
  }
  for (register int i = 1; i <= n; ++i) a[i] = read();
  sort(a + 1, a + 1 + n);
  for (register int i = 1; i < n; ++i) a[i] = a[i + 1] - a[i];
  f[1][1] = a[1];
  for (register int i = 2; i < n; ++i)
    for (register int j = 1; j <= min(i + 1 >> 1, k); ++j)
      f[i % 3][j] = min(f[(i - 1) % 3][j], f[(i - 2) % 3][j - 1] + a[i]);
  write(f[(n - 1) % 3][k]);
}
