#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
const int INF = 1e9 + 7;
struct cs {
  long long v;
  int id;
  bool operator<(const cs &a) const { return v > a.v; }
} t;
priority_queue<cs> Q;
long long a[N], ans;
int l[N], r[N];
bool ok[N];
int n, m;
int b[N];
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
  sort(b + 1, b + 1 + n);
  for (int i = 1; i < n; i++) {
    t.v = b[i + 1] - b[i];
    a[i] = t.v;
    t.id = i;
    l[i] = i - 1;
    r[i] = i + 1;
    Q.push(t);
  }
  n--;
  r[0] = 1;
  l[n + 1] = n;
  a[n + 1] = a[0] = INF;
  while (m--) {
    while (ok[Q.top().id]) Q.pop();
    t = Q.top();
    Q.pop();
    if (t.v < 0) break;
    ans += t.v;
    int x = t.id;
    a[x] = a[l[x]] + a[r[x]] - a[x];
    t.v = a[x];
    ok[l[x]] = ok[r[x]] = 1;
    l[x] = l[l[x]];
    r[l[x]] = x;
    r[x] = r[r[x]];
    l[r[x]] = x;
    Q.push(t);
  }
  cout << ans << endl;
}
