#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) {
  long long z = y;
  while (x % y != 0) {
    z = x % y;
    x = y;
    y = z;
  }
  return z;
}
int t[500105], T[500105];
pair<int, int> pt[500105];
bool vis[500105];
long long dp[2][500105][2];
void fmain(int ID) {
  scanf("%d%d", &k, &n);
  for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%d", t + i);
  sort(t + 1, t + 1 + n);
  for (int i = 1; i < n; i++) {
    T[i] = t[i + 1] - t[i];
    pt[i] = {T[i], i};
  }
  n--;
  sort(pt + 1, pt + 1 + n);
  for (int(i) = 1; (i) <= (int)(min(k * 3, n)); (i)++) vis[pt[i].second] = 1;
  for (int(x) = 0; (x) < (int)(2); (x)++)
    for (int(i) = 0; (i) < (int)(k + 1); (i)++) {
      for (int(z) = 0; (z) < (int)(2); (z)++) dp[x][i][z] = (1LL << 60);
    }
  dp[0][0][0] = 0;
  int t = 0, fg = 0;
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    if (vis[i]) {
      int cur = t ^ 1, pre = t;
      t ^= 1;
      for (int(j) = 0; (j) < (int)(k + 1); (j)++)
        for (int(z) = 0; (z) < (int)(2); (z)++) dp[cur][j][z] = (1LL << 60);
      for (int(j) = 0; (j) < (int)(k + 1); (j)++)
        dp[cur][j][0] = min(dp[pre][j][0], dp[pre][j][1]);
      for (int(j) = 0; (j) < (int)(k + 1); (j)++)
        if (dp[pre][j][0] != (1LL << 60)) {
          dp[cur][j + 1][1] = min(dp[cur][j + 1][1], dp[pre][j][0] + T[i]);
        }
      fg = 1;
    } else if (fg) {
      fg = 0;
      for (int(j) = 0; (j) < (int)(k + 1); (j)++)
        dp[t][j][0] = min(dp[t][j][0], dp[t][j][1]);
    }
  long long ans = min(dp[t][k][0], dp[t][k][1]);
  printf("%lld\n", ans);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
