#include <bits/stdc++.h>
using namespace std;
int a[500010], c[500010], d[500010], prv[500010], ans[500010], tmp[500010];
bool cmp(int i, int j) { return a[i] < a[j]; }
int main() {
  int k, n, i, nn, kk, j;
  scanf("%d%d", &k, &n);
  for (i = 1; i <= n; i++) scanf("%d", a + i), c[i] = i;
  sort(a + 1, a + n + 1);
  for (i = 1; i < n; i++) a[i] = a[i + 1] - a[i];
  sort(c + 1, c + n, cmp);
  nn = min(n - 1, 3 * k);
  for (i = 1; i <= nn; i++) d[i] = c[i];
  sort(d + 1, d + nn + 1);
  for (i = 0; i <= k; i++) prv[i] = 1e9;
  for (i = 0; i <= k; i++) ans[i] = 1e9;
  ans[1] = a[d[1]];
  for (i = 2; i <= nn; i++) {
    for (kk = 1; kk <= k; kk++) {
      if (kk == 1)
        tmp[1] = min(a[d[i]], ans[1]);
      else {
        if (d[i] == d[i - 1] + 1)
          tmp[kk] = min(ans[kk], prv[kk - 1] + a[d[i]]);
        else
          tmp[kk] = min(ans[kk], ans[kk - 1] + a[d[i]]);
      }
    }
    for (j = 1; j <= kk; j++) prv[j] = ans[j];
    for (j = 1; j <= kk; j++) ans[j] = tmp[j];
  }
  printf("%d\n", ans[k]);
}
