#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <typename T1, typename T2>
inline bool upmax(T1& a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool upmin(T1& a, T2 b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = (int)2e9;
const int maxn = 5e5 + 5, inf = 2e9;
int a[maxn];
bool cmp(const pair<int, int>& a, const pair<int, int>& b) {
  return a.second - a.first < b.second - b.first;
}
int dp[2][5001][2];
const int BUBEN = 10500;
int main() {
  srand(time(0));
  ios_base::sync_with_stdio(0);
  int k, n;
  cin >> k >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  vector<pair<int, int> > rng;
  for (int i = 0; i + 1 < n; i++) {
    rng.push_back(make_pair(a[i], a[i + 1]));
  }
  sort((rng).begin(), (rng).end(), cmp);
  while (rng.size() > BUBEN) rng.pop_back();
  sort((rng).begin(), (rng).end());
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 5001; j++)
      for (int k = 0; k < 2; k++) dp[i][j][k] = INF;
  int t = 0;
  dp[0][0][0] = 0;
  for (int i = 0; i < rng.size(); i++) {
    for (int j = 0; j <= k; j++)
      for (int tk = 0; tk < 2; tk++) {
        if (dp[t][j][tk] == INF) continue;
        upmin(dp[t ^ 1][j][0], dp[t][j][tk]);
        bool ok = (j < k) && (tk == 0 || (rng[i - 1].second != rng[i].first));
        if (ok)
          upmin(dp[t ^ 1][j + 1][1],
                dp[t][j][tk] + rng[i].second - rng[i].first);
      }
    for (int j = 0; j <= k; j++)
      for (int tk = 0; tk < 2; tk++) dp[t][j][tk] = INF;
    t ^= 1;
  }
  cout << min(dp[t][k][0], dp[t][k][1]);
  return 0;
}
