#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5;
const int MAXK = 5e3;
const int LOGN = 0;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 10;
const long long INFLL = (long long)1e18 + 10;
int N, K;
int T[MAXN + 10];
long long diff[MAXN + 10];
pair<int, int> aux[MAXN + 10];
long long dp[MAXK + 10][MAXK + 10];
long long tmp[MAXK + 10];
int nx[MAXN + 10];
int pr[MAXN + 10];
void read() {
  cin >> K >> N;
  for (int(i) = 0; (i) < (N); ++(i)) cin >> T[i];
  return;
}
void dbgdp() {
  for (int(i) = 1; (i) <= (K); ++(i)) {
    for (int(j) = 0; (j) < (N - 1); ++(j)) cout << dp[i][j] << " ";
    cout << "\n";
  }
  cout << "\n";
  return;
}
void run() {
  sort(T, T + N);
  for (int(i) = 0; (i) < (N - 1); ++(i)) {
    diff[i] = T[i + 1] - T[i];
    aux[i] = pair<int, int>(diff[i], i);
    pr[i] = i - 1;
    nx[i] = i + 1;
  }
  sort(aux, aux + N - 1);
  for (int i = N - 2; i > 2 * K; --i) {
    diff[aux[i].second] = -1;
  }
  for (int(i) = 0; (i) < (N - 1); ++(i)) {
    if (diff[i] == -1) {
      if (i) nx[pr[i]] = nx[i];
      if (i < N - 2) pr[nx[i]] = pr[i];
    }
  }
  for (int i = 0; i < N - 1; i++) {
    if (diff[i] != -1) {
      int bi, bbi;
      bi = pr[i];
      if (bi == i - 1) {
        if (bi >= 0)
          bi = pr[bi];
        else
          bi = -1;
      }
      if (bi >= 0)
        bbi = pr[bi];
      else
        bbi = -1;
      int j = 1;
      if (bi >= 0) {
        for (; j <= K && dp[j][bi]; ++j) {
          tmp[j] = min(dp[j - 1][bi] + diff[i], dp[j][bi]);
          if (dp[j - 1][bbi]) tmp[j] = min(tmp[j], dp[j - 1][bbi] + diff[i]);
          if (dp[j][bbi]) tmp[j] = min(tmp[j], dp[j][bbi]);
        }
        tmp[j] = dp[j - 1][bi] + diff[i];
        if (dp[j - 1][bbi]) tmp[j] = min(tmp[j], dp[j - 1][bbi] + diff[i]);
      } else {
        tmp[j] = diff[i];
      }
      for (int c = 1; c <= j; ++c) dp[c][i] = tmp[c];
    }
  }
  long long ans = INFLL;
  for (int i = N - 2; i >= 0; --i) {
    if (dp[K][i]) {
      ans = min(ans, dp[K][i]);
    }
  }
  cout << ans;
  cout << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  read();
  run();
  return 0;
}
