#include <bits/stdc++.h>
using namespace std;
long long a[500005], s[500005];
long long f[500005], ch[500005];
long long n, k, m;
bool check(long long x) {
  for (long long i = 2; i <= n; i++) {
    long long t1 = f[i - 2] + ch[i] - x;
    if (f[i - 1] < t1)
      f[i] = f[i - 1], s[i] = s[i - 1];
    else if (f[i - 1] > t1)
      f[i] = t1, s[i] = s[i - 2] + 1;
    else
      f[i] = f[i - 1], s[i] = max(s[i - 1], s[i - 2] + 1);
  }
  return s[n] >= k;
}
signed main() {
  cin >> k >> n;
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
  sort(a + 1, a + n + 1);
  long long l = 0, r;
  for (long long i = 2; i <= n; i++) ch[i] = a[i] - a[i - 1];
  r = a[n] - a[1];
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (check(mid))
      m = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  check(m);
  cout << f[n] + m * k;
}
