#include <bits/stdc++.h>
using namespace std;
inline int Gcd(int X, int Y) { return Y ? Gcd(Y, X % Y) : X; }
inline long long Gcd(long long X, long long Y) { return Y ? Gcd(Y, X % Y) : X; }
inline int Pow(int base, long long exp, int _mod) {
  int _ans = 1;
  for (; exp; exp >>= 1, base = (long long)base * base % _mod)
    exp& 1 ? _ans = (long long)_ans * base % _mod : 0;
  return _ans;
}
inline long long Pow(long long base, long long exp, long long _mod) {
  long long _ans = 1;
  for (; exp; exp >>= 1, base = base * base % _mod)
    exp& 1 ? _ans = _ans * base % _mod : 0;
  return _ans;
}
const int INF = 0x3f3f3f3f;
int n, k;
long long ans;
long long a[500009];
int l[500009], r[500009];
int vis[500009];
priority_queue<pair<long long, int>, vector<pair<long long, int> >,
               greater<pair<long long, int> > >
    pq;
int main() {
  scanf("%d%d", &k, &n);
  for (int i = 1; i <= (n); ++i) scanf("%d", a + i);
  sort(a + 1, a + n + 1);
  --n;
  for (int i = 1; i <= (n); ++i) a[i] = a[i + 1] - a[i];
  for (int i = 1; i <= (n); ++i)
    pq.push(make_pair(a[i], i)), l[i] = i - 1, r[i] = i + 1;
  r[0] = 1;
  l[n + 1] = n;
  a[0] = a[n + 1] = 0x3f3f3f3f3f3f3f3f;
  for (int i = 1; i <= (k); ++i) {
    while (vis[pq.top().second]) pq.pop();
    pair<long long, int> p = pq.top();
    pq.pop();
    ans += p.first;
    int x = p.second;
    a[x] = a[l[x]] + a[r[x]] - a[x];
    p.first = a[x];
    vis[l[x]] = vis[r[x]] = 1;
    l[x] = l[l[x]];
    r[l[x]] = x;
    r[x] = r[r[x]];
    l[r[x]] = x;
    pq.push(p);
  }
  printf("%lld", ans);
  return 0;
}
