#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5 + 100l;
long long L[N], R[N];
long long a[N];
long long vis[N];
void remove(long long x) {
  R[L[x]] = L[x];
  L[R[x]] = R[x];
}
signed main() {
  long long k, n;
  cin >> k >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  n--;
  for (long long i = 1; i <= n; i++) a[i] = a[i + 1] - a[i];
  for (long long i = 1; i <= n; i++) L[i] = i - 1, R[i] = i + 1;
  multiset<pair<long long, long long> > s;
  for (long long i = 1; i <= n; i++) s.insert({a[i], i});
  long long ans = 0;
  while (s.size()) {
    auto now = *s.begin();
    s.erase(s.begin());
    long long x = now.second;
    if (vis[x]) continue;
    vis[L[x]] = vis[R[x]] = 1;
    ans += now.first;
    if (--k <= 0) break;
    if (L[x] == 0 || R[x] == n + 1) continue;
    now.first = a[x] = a[R[x]] + a[L[x]] - a[x];
    L[x] = L[L[x]];
    R[L[x]] = x;
    R[x] = R[R[x]];
    L[R[x]] = x;
    s.insert(now);
  }
  cout << ans << '\n';
}
