#include <bits/stdc++.h>
using namespace std;
mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template <typename T>
inline void chkmax(T &x, T y) {
  if (x < y) x = y;
}
template <typename T>
inline void chkmin(T &x, T y) {
  if (x > y) x = y;
}
inline int read() {
  int x = 0;
  char c = getchar();
  while (c < 48) c = getchar();
  while (c > 47) x = x * 10 + (c ^ 48), c = getchar();
  return x;
}
const int maxn = 5e5 + 10;
int n, k, A[maxn];
struct DSU {
  int par[maxn];
  void init() {
    for (int i = (0), iend = (maxn - 1); i <= iend; ++i) par[i] = i;
  }
  int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
} pre, suf;
int cnt[maxn];
bool vis[maxn];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    Q;
void solve() {
  cin >> k >> n;
  for (int i = (1), iend = (n); i <= iend; ++i) A[i] = read();
  sort(A + 1, A + n + 1);
  for (int i = (1), iend = (n - 1); i <= iend; ++i) A[i] = A[i + 1] - A[i];
  A[n--] = 0;
  for (int i = (n + 1), iend = (2); i >= iend; --i) A[i] = A[i - 1];
  A[1] = 1e9, A[n += 2] = 1e9;
  pre.init(), suf.init();
  for (int i = (1), iend = (n); i <= iend; ++i) Q.push({A[i], i}), cnt[i] = 1;
  int res = 0;
  while (k) {
    pair<int, int> p = Q.top();
    int pos = p.second;
    Q.pop();
    if (vis[pos]) continue;
    k -= cnt[pos];
    int l = pre.find(pos - 1);
    int r = suf.find(pos + 1);
    res += A[pos];
    A[pos] = A[l] + A[r] - A[pos];
    cnt[pos] = cnt[l] + cnt[r] - cnt[pos];
    Q.push({A[pos], pos});
    vis[l] = vis[r] = 1, cnt[l] = cnt[r] = 0, A[l] = A[r] = 0;
    if (l >= 1) pre.par[pre.find(l)] = pre.find(l - 1);
    if (l <= n) suf.par[suf.find(l)] = suf.find(l + 1);
    if (r >= 1) pre.par[pre.find(r)] = pre.find(r - 1);
    if (r <= n) suf.par[suf.find(r)] = suf.find(r + 1);
  }
  cout << res << endl;
}
int main() {
  solve();
  return 0;
}
