#include <bits/stdc++.h>
int n, m, t, max_delta, n_c, a[500005], b[500005], c[500005], f[3][5005];
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  std::sort(a + 1, a + n + 1);
  for (int i = 1; i < n; ++i) b[i] = a[i + 1] - a[i];
  std::sort(b + 1, b + n);
  max_delta = b[std::min(n - 1, 3 * m)];
  for (int i = 1, pre = 0; i < n; ++i) {
    if (a[i + 1] - a[i] <= max_delta) {
      if (!pre) c[++n_c] = a[i];
      c[++n_c] = a[i + 1];
      pre = 1;
    } else
      pre = 0;
  }
  memset(f, 0x7f, sizeof(f));
  f[0][0] = f[1][0] = f[2][0] = 0;
  for (int i = 1; i <= n_c; ++i, t = (t + 1) % 3)
    for (int j = 1; j <= m && j <= (i >> 1); ++j) {
      f[t][j] =
          std::min(f[(t + 2) % 3][j], f[(t + 1) % 3][j - 1] + c[i] - c[i - 1]);
    }
  printf("%d\n", f[(t + 2) % 3][m]);
}
