#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x;
  cin >> x;
  return x;
}
template <class Flow, class Cost>
struct MinCostFlow {
  struct Edge {
    int v, inv;
    Flow c, f;
    Cost w;
    Edge() {}
    Edge(int v, Flow c, Cost w, int inv) : v(v), inv(inv), c(c), f(0), w(w) {}
  };
  static const int MAX_K = 5001;
  static const int MAX_N = 2 * (2 * MAX_K + 100) + 100;
  static const Cost oo = 1e9 + 99;
  int n, s, t;
  vector<Edge> e[MAX_N];
  Cost d[MAX_N];
  int p[MAX_N], pEdge[MAX_N], state[MAX_N];
  void init(int nn, int ss, int tt) {
    n = nn, s = ss, t = tt;
    for (long long i = (1); i <= (n); ++i) e[i].clear();
  }
  void addEdge(int u, int v, Flow c, Cost w) {
    int i = int(e[u].size()), j = int(e[v].size());
    e[u].push_back(Edge(v, c, w, j));
    e[v].push_back(Edge(u, 0, -w, i));
  }
  bool findPath() {
    for (long long i = (1); i <= (n); ++i) {
      d[i] = oo;
      state[i] = 0;
      p[i] = pEdge[i] = -1;
    }
    d[s] = 0;
    deque<int> q;
    q.push_back(s);
    while (!q.empty()) {
      int u = q.front();
      q.pop_front();
      state[u] = 2;
      for (long long i = (0); i <= (int(e[u].size()) - 1); ++i)
        if (e[u][i].f < e[u][i].c) {
          int v = e[u][i].v;
          Cost tmp = d[u] + e[u][i].w;
          if (tmp >= d[v]) continue;
          d[v] = tmp;
          p[v] = u;
          pEdge[v] = i;
          if (state[v] == 0)
            q.push_back(v);
          else if (state[v] == 2)
            q.push_front(v);
          state[v] = 1;
        }
    }
    return p[t] > -1;
  }
  pair<Flow, Cost> getFlow(Flow limit = oo) {
    Flow flow = 0;
    Cost cost = 0;
    while (findPath()) {
      Flow add = limit - flow;
      if (add <= 0) break;
      for (int v = t; v != s; v = p[v]) {
        int u = p[v], i = pEdge[v];
        add = min(add, e[u][i].c - e[u][i].f);
      }
      flow += add;
      for (int v = t; v != s; v = p[v]) {
        int u = p[v], i = pEdge[v];
        e[u][i].f += add;
        e[v][e[u][i].inv].f -= add;
        cost += Cost(add) * e[u][i].w;
      }
    }
    return make_pair(flow, cost);
  }
};
const int MAX_N = 5e5 + 55;
int N, K;
int a[MAX_N], id[MAX_N];
MinCostFlow<int, int> minCostFlow;
bool isIn[MAX_N], isOut[MAX_N];
vector<pair<int, int> > b;
vector<pair<pair<int, int>, int> > edges;
int solve() {
  int s = 1, t0 = 2, t = 3, nNode = 3;
  for (int i = 0; i < N; ++i) isIn[i] = isOut[i] = false;
  int limit = min(2 * K + 100, (int)b.size());
  edges.clear();
  for (int i = 0; i < limit; ++i) {
    int cost = b[i].first, u = b[i].second;
    int v = u + 1;
    if (u & 1) swap(u, v);
    isIn[u] = true;
    isOut[v] = true;
    edges.push_back(make_pair(pair<int, int>(u, v), cost));
  }
  for (int i = 0; i < N; ++i)
    if (isIn[i] || isOut[i]) id[i] = ++nNode;
  minCostFlow.init(nNode, s, t);
  for (int i = 0; i < N; ++i) {
    if (isIn[i]) minCostFlow.addEdge(s, id[i], 1, 0);
    if (isOut[i]) minCostFlow.addEdge(id[i], t0, 1, 0);
  }
  for (__typeof(edges.begin()) it = edges.begin(); it != edges.end(); it++) {
    int u = it->first.first, v = it->first.second;
    int cost = it->second;
    minCostFlow.addEdge(id[u], id[v], 1, cost);
  }
  minCostFlow.addEdge(t0, t, K, 0);
  pair<int, int> flow = minCostFlow.getFlow();
  return flow.second;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(9);
  cout.setf(ios::fixed, ios::floatfield);
  cin >> K >> N;
  for (int i = 0; i < N; ++i) cin >> a[i];
  sort(a, a + N);
  for (int i = 0; i < N - 1; ++i)
    b.push_back(pair<int, int>(a[i + 1] - a[i], i));
  sort(b.begin(), b.end());
  cout << solve() << '\n';
  return 0;
}
