#include <bits/stdc++.h>
using namespace std;
const int NMAX = 10100, KMAX = 5005;
unsigned int dp[NMAX][KMAX];
const unsigned int INF = 0x3f3f3f3f;
void init() { memset(dp, INF, sizeof dp); }
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  init();
  int K, N;
  cin >> K >> N;
  vector<int> vi(N);
  for (int& ii : vi) cin >> ii;
  sort(vi.begin(), vi.end());
  vector<pair<int, int> > v(N - 1);
  vector<pair<int, int> > cpy(N - 1);
  int last = vi[0];
  for (int i = 0; i < N - 1; ++i) {
    int vv = vi[i + 1];
    v[i].first = vv - last;
    v[i].second = 0;
    cpy[i] = pair<int, int>(v[i].first, i);
    last = vv;
  }
  sort(cpy.begin(), cpy.end());
  for (int i = 0; i < 2 * K + 10 && i < (N - 1); ++i) {
    v[cpy[i].second].second = 1;
  }
  vector<unsigned int> w;
  int last_type = 0;
  for (auto& p : v) {
    if (p.second == 1) {
      unsigned int tval = p.first;
      if (!last_type) {
        tval |= (1 << 31);
      }
      w.push_back(tval);
      last_type = 1;
    } else {
      last_type = 0;
    }
  }
  dp[0][0] = 0;
  for (int i = 1; i <= w.size(); ++i) {
    for (int j = 0; j <= K; ++j) {
      dp[i][j] = dp[i - 1][j];
      unsigned int tval = w[i - 1] & ((((unsigned int)1) << 31) - 1);
      bool free_prev = (w[i - 1] & ((unsigned int)1 << 31)) != 0;
      if (free_prev || (i == 1 && j == 1))
        dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + tval);
      if (j > 0 && i > 1) dp[i][j] = min(dp[i][j], dp[i - 2][j - 1] + tval);
    }
  }
  unsigned int best = INF;
  for (int i = 0; i <= w.size(); ++i) {
    best = min(best, dp[i][K]);
  }
  cout << best << endl;
  return 0;
}
