#include <bits/stdc++.h>
using namespace std;
const int N = 500000 + 10;
const int M = 1e9 + 7;
const double eps = 1e-6;
const long long inf = 1e18;
const double PI(acos(-1.0));
int k, n;
int a[N];
pair<long long, int> f[N];
pair<long long, int> judge(int cost) {
  for (int i = (2); i <= (n); i++) {
    f[i] = min(f[i - 1], make_pair(f[i - 2].first - cost + a[i] - a[i - 1],
                                   f[i - 2].second + 1));
  }
  return f[n];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> k >> n;
  for (int i = (1); i <= (n); i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  int l = 0, r = 1e9, m;
  pair<long long, int> t;
  while (l <= r) {
    m = (l + r) >> 1;
    t = judge(m);
    if (t.second > k)
      r = m - 1;
    else
      l = m + 1;
  }
  t = judge(l - 1);
  cout << t.first + 1LL * (l - 1) * k << endl;
}
