#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500500, MAXK = 5005;
const int INF = 1e9 + 50;
int rng(pair<int, int> a) { return a.second - a.first; }
bool comp(pair<int, int> a, pair<int, int> b) { return rng(a) < rng(b); }
bool collide(pair<int, int> a, pair<int, int> b) {
  return a.second == b.first || a.first == b.second;
}
int n, k, T[MAXN];
vector<pair<int, int> > S;
int dp[2 * MAXK][MAXK];
int solve(int p, int rem) {
  if (rem == 0) return 0;
  if (p >= n) return INF;
  int &ret = dp[p][rem];
  if (ret != -1) return ret;
  int skip = solve(p + 1, rem);
  int keep = rng(S[p]) + ((p < n - 1 && !collide(S[p], S[p + 1]))
                              ? solve(p + 1, rem - 1)
                              : solve(p + 2, rem - 1));
  return ret = min(skip, keep);
}
int main() {
  while (scanf("%d %d", &k, &n) >= 1) {
    for (int i = (0); i < (int)(n); i++) scanf("%d", &T[i]);
    sort(T, T + n);
    S.clear();
    for (int i = (0); i < (int)(n - 1); i++) S.push_back({T[i], T[i + 1]});
    sort(S.begin(), S.end(), comp);
    S.resize(min(2 * k + 5, n - 1));
    sort(S.begin(), S.end());
    n = ((int)S.size());
    for (int i = (0); i < (int)(2 * MAXK); i++)
      for (int j = (0); j < (int)(MAXK); j++) dp[i][j] = -1;
    printf("%d\n", solve(0, k));
  }
  return 0;
}
