#include <bits/stdc++.h>
using namespace std;
long long res;
long long f[500005];
int m, n;
int df[500005];
int cnt[500005];
int base[500005];
bool check(int x) {
  x *= -1;
  for (int i = 2; i <= n; ++i) {
    if (f[i - 1] < f[i - 2] + df[i] + x)
      f[i] = f[i - 1], cnt[i] = cnt[i - 1];
    else
      f[i] = f[i - 2] + (long long)df[i] + (long long)x,
      cnt[i] = cnt[i - 2] + 1;
    if (f[i - 1] == f[i - 2] + df[i] + x)
      cnt[i] = max(cnt[i - 1], cnt[i - 2] + 1);
  }
  res = f[n] - (long long)x * m;
  return (bool)(cnt[n] >= m);
}
int main() {
  cin >> m >> n;
  for (int i = 1; i <= n; ++i) scanf("%d", &base[i]);
  sort(base + 1, base + n + 1);
  for (int i = 1; i <= n; ++i) df[i] = base[i] - base[i - 1];
  int l = 0, r = 1e9, mid, ans;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  check(ans);
  cout << res << endl;
  return 0;
}
