#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    pq;
int a[600005], ans;
int n, k, pre[600005], nxt[600005];
int main() {
  scanf("%d%d", &k, &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i < n; ++i)
    a[i] = a[i + 1] - a[i], pq.push(pair<int, int>(a[i], i));
  for (int i = 0; i <= n; ++i) pre[i] = i - 1, nxt[i] = i + 1;
  a[0] = a[n] = (1 << 30), pre[0] = 0, nxt[n] = 0;
  for (int i = 1; i <= k; ++i) {
    while (pq.size() && a[pq.top().second] != pq.top().first) pq.pop();
    if (pq.empty()) break;
    pair<int, int> s = pq.top();
    pq.pop();
    ans += s.first;
    int x = s.second;
    int l = pre[x], r = nxt[x];
    a[x] = l && r ? min((1 << 30), a[l] + a[r] - a[x]) : (1 << 30);
    pq.push(pair<int, int>(a[x], x));
    a[l] = a[r] = (1 << 30);
    nxt[pre[x] = pre[l]] = x;
    pre[nxt[x] = nxt[r]] = x;
  }
  printf("%d", ans);
}
