#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int k, n, a[N], Last[N], Next[N];
set<pair<int, int> > S;
long long ans = 0;
void del(int x) {
  Next[Last[x]] = Next[x];
  Last[Next[x]] = Last[x];
  S.erase(make_pair(a[x], x));
}
void gao(int x) {
  int pre = Last[x], nxt = Next[x];
  S.erase(make_pair(a[x], x));
  int now = -a[x];
  now += a[pre];
  if (pre) del(pre);
  now += a[nxt];
  if (nxt < n) del(nxt);
  a[x] = now;
  S.insert(make_pair(a[x], x));
}
int main() {
  cin >> k >> n;
  for (int i = (1); i < (n + 1); ++i) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (int i = (1); i < (n); ++i) {
    a[i] = a[i] - a[i + 1];
    Last[i] = i - 1;
    Next[i] = i + 1;
    S.insert(make_pair(a[i], i));
  }
  a[0] = a[n] = -1e9;
  Last[n] = n - 1;
  Next[0] = 1;
  while (k--) {
    pair<int, int> now = *S.rbegin();
    ans += now.first;
    gao(now.second);
  }
  cout << -ans << "\n";
  return 0;
}
