#include <bits/stdc++.h>
using namespace std;
long long INF = 1e18;
signed main() {
  long long k, n;
  cin >> k >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  vector<long long> p(n - 1);
  for (long long i = 0; i < n - 1; i++) p[i] = v[i + 1] - v[i];
  vector<pair<long long, long long> > x;
  for (long long i = 0; i < n - 1; i++) x.push_back(make_pair(p[i], i));
  sort(x.begin(), x.end());
  long long val = min((long long)20000, n - 1);
  while (x.size() > val) x.pop_back();
  for (long long i = 0; i < x.size(); i++) swap(x[i].first, x[i].second);
  sort(x.begin(), x.end());
  long long dp[k + 1][2];
  for (long long i = 0; i <= k; i++)
    for (long long j = 0; j < 2; j++) dp[i][j] = INF;
  dp[0][0] = 0;
  dp[1][1] = x[0].second;
  for (long long i = 1; i < x.size(); i++) {
    long long dp2[k + 1][2];
    for (long long q = 0; q <= k; q++)
      for (long long j = 0; j < 2; j++) dp2[q][j] = INF;
    for (long long q = 0; q <= k; q++) {
      dp2[q][0] = min(dp2[q][0], dp[q][0]);
      dp2[q][0] = min(dp2[q][0], dp[q][1]);
      if (q > 0) dp2[q][1] = min(dp2[q][1], dp[q - 1][0] + x[i].second);
      if (q > 0)
        if (x[i].first - x[i - 1].first > 1)
          dp2[q][1] = min(dp2[q][1], dp[q - 1][1] + x[i].second);
    }
    for (long long q = 0; q <= k; q++)
      for (long long j = 0; j < 2; j++) dp[q][j] = dp2[q][j];
  }
  cout << min(dp[k][0], dp[k][1]) << endl;
  return 0;
}
