#include <bits/stdc++.h>
using namespace std;
struct me {
  int value;
  int pos;
} v[500000 + 5];
int vv[500000 + 5];
bool f[500000 + 5];
int dp1[2][5005], dp2[5005];
bool cmp(struct me a, struct me b) { return a.value < b.value; }
int main() {
  int k, n;
  scanf("%d%d", &k, &n);
  for (int i = 1; i <= n; i++) scanf("%d", &vv[i]);
  sort(vv + 1, vv + 1 + n);
  for (int i = 1; i < n; i++) {
    v[i].value = vv[i + 1] - vv[i];
    vv[i] = vv[i + 1] - vv[i];
    v[i].pos = i;
  }
  sort(v + 1, v + n, cmp);
  for (int i = 1; i <= min(3 * k, n - 1); i++) {
    f[v[i].pos] = true;
  }
  memset(dp1[0], 0x3f, sizeof(dp1[0]));
  memset(dp1[1], 0x3f, sizeof(dp1[1]));
  memset(dp2, 0x3f, sizeof(dp2));
  dp1[0][0] = 0;
  dp1[1][0] = 0;
  dp2[0] = 0;
  for (int i = 1; i < n; i++) {
    if (f[i] == false && n == 500000) continue;
    if (i == 1)
      dp1[1][1] = vv[i];
    else {
      for (int j = 1; j <= min(k, (i + 1) / 2); j++)
        dp2[j] = min(dp1[1][j], dp1[0][j - 1] + vv[i]);
      for (int j = 1; j <= min(k, (i + 1) / 2); j++) {
        dp1[0][j] = dp1[1][j];
        dp1[1][j] = dp2[j];
      }
      memset(dp2, 0x3f, sizeof(dp2));
      dp2[0] = 0;
    }
  }
  printf("%d\n", dp1[1][k]);
  return 0;
}
