#include <bits/stdc++.h>
using namespace std;
long long int dp[5005][2];
long long int inf = 1000000000000000000;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, k;
  cin >> k >> n;
  vector<long long int> b;
  for (long long int i = 0; i < n; i++) {
    long long int z;
    cin >> z;
    b.push_back(z);
  }
  sort(b.begin(), b.end());
  vector<long long int> a;
  for (long long int i = 1; i < n; i++) {
    a.push_back(b[i] - b[i - 1]);
  }
  vector<pair<long long int, long long int> > v;
  for (long long int i = 1; i <= n - 1; i++) {
    long long int z;
    z = a[i - 1];
    v.push_back(make_pair(z, i));
  }
  sort(v.begin(), v.end());
  vector<pair<long long int, long long int> > u;
  u.push_back(make_pair(0, 0));
  for (long long int i = 0; i < min(3 * k, n - 1); i++) {
    u.push_back(make_pair(v[i].second, v[i].first));
  }
  sort(u.begin(), u.end());
  n = min(n - 1, 3 * k);
  for (long long int i = 0; i <= k; i++) {
    dp[i][0] = inf;
    dp[i][1] = inf;
  }
  dp[0][0] = 0;
  dp[0][1] = 0;
  for (long long int i = 1; i <= n; i++) {
    long long int dp2[k + 2][2];
    for (long long int j = 0; j <= k; j++) {
      dp2[j][0] = inf;
      dp2[j][1] = inf;
    }
    for (long long int j = 0; j <= k; j++) {
      if (u[i].first == u[i - 1].first + 1) {
        dp2[j][0] = min(dp2[j][0], min(dp[j][0], dp[j][1]));
        if (j) {
          dp2[j][1] = min(dp2[j][1], dp[j - 1][0] + u[i].second);
        }
      } else {
        dp2[j][0] = min(dp2[j][0], min(dp[j][0], dp[j][1]));
        if (j) {
          dp2[j][1] =
              min(dp2[j][1], min(dp[j - 1][0], dp[j - 1][1]) + u[i].second);
        }
      }
    }
    for (long long int j = 0; j <= k; j++) {
      dp[j][0] = dp2[j][0];
      dp[j][1] = dp2[j][1];
    }
  }
  cout << min(dp[k][0], dp[k][1]);
}
