#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int NINF = 0xc0c0c0c0;
const int maxn = 5e5 + 5;
long long a[maxn], d[maxn], pre[maxn], nxt[maxn];
bool vis[maxn];
int main() {
  std::ios::sync_with_stdio(false);
  int k, n;
  while (cin >> k >> n) {
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                   greater<pair<long long, int> > >
        pq;
    for (int i = 1; i < n; i++) {
      d[i] = a[i] - a[i - 1];
      pre[i] = i - 1;
      nxt[i] = i + 1;
      vis[i] = 0;
      pq.push(make_pair(d[i], i));
    }
    d[0] = d[n] = INF;
    long long ans = 0;
    for (int i = 0; i < k; i++) {
      while (true) {
        if (pq.empty()) break;
        int i = pq.top().second;
        pq.pop();
        if (vis[i]) continue;
        ans += d[i];
        d[i] = -d[i];
        vis[pre[i]] = true;
        d[i] += d[pre[i]];
        pre[i] = pre[pre[i]];
        nxt[pre[i]] = i;
        vis[nxt[i]] = true;
        d[i] += d[nxt[i]];
        nxt[i] = nxt[nxt[i]];
        pre[nxt[i]] = i;
        pq.push(make_pair(d[i], i));
        break;
      }
    }
    cout << ans << endl;
  }
}
