#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rnd(long long l, long long r) { return l + rng() % (r - l + 1); }
const long long N = 5e5 + 5;
const long long K = 5005;
long long n, a[N], k;
long long f[2][K][2];
void minimize(long long &x, long long y) { x = min(x, y); }
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> k >> n;
  for (long long i = 1, __c = n; i <= __c; ++i) cin >> a[i];
  vector<pair<long long, long long> > w;
  sort(a + 1, a + n + 1);
  for (long long i = 1, __c = n - 1; i <= __c; ++i)
    w.emplace_back(a[i + 1] - a[i], i);
  sort(begin(w), end(w));
  long long m = min((long long)w.size(), 3 * k);
  w.resize(m);
  for (auto &v : w) swap(v.first, v.second);
  w.push_back(make_pair(-1, 0));
  sort(begin(w), end(w));
  memset(f, 0x3f, sizeof(f));
  f[0][0][0] = 0;
  long long now = 0;
  for (long long i = 1, __c = m; i <= __c; ++i) {
    f[now][0][0] = f[now][0][1] = 0;
    for (long long j = 1, __c = k; j <= __c; ++j) {
      minimize(f[now ^ 1][j][0], f[now][j][0]);
      minimize(f[now ^ 1][j][0], f[now][j][1]);
      minimize(f[now ^ 1][j][1], f[now ^ 1][j][0]);
      minimize(f[now ^ 1][j][1], f[now][j - 1][0] + w[i].second);
      if (w[i].first != w[i - 1].first + 1)
        minimize(f[now ^ 1][j][1], f[now][j - 1][1] + w[i].second);
    }
    now ^= 1;
  }
  cout << f[now][k][1] << '\n';
}
