#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void Read(T &x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}
template <typename T>
inline bool CheckMax(T &a, const T &b) {
  return a < b ? a = b, true : false;
}
template <typename T>
inline bool CheckMin(T &a, const T &b) {
  return a > b ? a = b, true : false;
}
const int N = 500005;
const long long inf = 1LL << 60;
priority_queue<pair<long long, int>, vector<pair<long long, int>>,
               greater<pair<long long, int>>>
    q;
int n, m, b[N], nxt[N], pre[N];
long long ans, a[N];
int main() {
  Read(m), Read(n);
  for (int i = 1; i <= n; ++i) {
    Read(b[i]);
  }
  sort(b + 1, b + n + 1), --n;
  for (int i = 1; i <= n; ++i) {
    a[i] = b[i + 1] - b[i], pre[i] = i - 1, nxt[i] = i + 1;
    q.push(make_pair(a[i], i));
  }
  nxt[n] = 0;
  for (int i = 1; i <= m; ++i) {
    for (; q.top().first != a[q.top().second]; q.pop())
      ;
    int x = q.top().second, l = pre[x], r = nxt[x];
    ans += a[x], q.pop();
    pre[nxt[x] = nxt[r]] = x, nxt[pre[x] = pre[l]] = x;
    a[x] = l && r ? min(inf, a[l] + a[r] - a[x]) : inf, a[l] = a[r] = inf;
    q.push(make_pair(a[x], x));
  }
  printf("%lld\n", ans);
  return 0;
}
