#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int maxn = 500000;
int n, k;
int t[maxn + 11], a[maxn + 11];
pair<long long, int> f[maxn + 11][2];
pair<long long, int> check(long long mid) {
  f[0][0] = make_pair(0, 0);
  f[0][1] = make_pair(inf, 1);
  for (int i = 1; i <= n; i++) {
    f[i][0] = min(f[i - 1][0], f[i - 1][1]);
    f[i][1] = make_pair(f[i - 1][0].first + a[i] - mid, f[i - 1][0].second + 1);
  }
  return min(f[n][0], f[n][1]);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> k >> n;
  for (int i = 1; i <= n; i++) cin >> t[i];
  sort(t + 1, t + 1 + n);
  for (int i = 1; i < n; i++) a[i] = t[i + 1] - t[i];
  --n;
  long long l = 0, r = 1e12;
  pair<long long, int> ans;
  long long K;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    pair<long long, int> pi = check(mid);
    if (pi.second <= k)
      K = mid, ans = pi, l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%lld\n", ans.first + K * k);
}
