#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool cmax(T& x, T y) {
  return y > x ? x = y, true : false;
}
template <typename T>
inline bool cmin(T& x, T y) {
  return y < x ? x = y, true : false;
}
template <typename T>
inline T dmax(T x, T y) {
  return x > y ? x : y;
}
template <typename T>
inline T dmin(T x, T y) {
  return x < y ? x : y;
}
const int MAXN = 5e5 + 5;
const int oo = 0x3f3f3f3f;
int N, M, a[MAXN];
pair<long long, int> f[MAXN];
pair<long long, int> calc(int o, long long k) {
  pair<long long, int> w = f[o - 2];
  w.first += a[o] - a[o - 1] - k;
  w.second++;
  return w;
}
pair<long long, int> calc(long long k) {
  f[0] = make_pair(0, 0);
  for (int i = 1; i <= N; i++) {
    f[i] = f[i - 1];
    if (i - 1) cmin(f[i], calc(i, k));
  }
  return f[N];
}
int main() {
  scanf("%d%d", &M, &N);
  for (int i = 1; i <= N; i++) scanf("%d", &a[i]);
  sort(a + 1, a + N + 1);
  int le = 0, ri = 1e9, mi;
  while (le + 1 < ri) {
    mi = (le + ri) >> 1;
    if (calc(mi).second <= M)
      le = mi;
    else
      ri = mi;
  }
  long long ans = oo;
  for (int i = le; i <= ri; i++) {
    pair<long long, int> w = calc(i);
    if (w.second <= M) cmin(ans, w.first + (long long)M * i);
  }
  printf("%lld\n", ans);
  return 0;
}
