#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long maxn = 100050;
long long a[maxn], dp[5200][5200];
signed main() {
  long long n, k;
  cin >> k >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  vector<pair<long long, long long> > v, tmp;
  for (long long i = 1; i < n; i++) {
    v.push_back({a[i + 1] - a[i], i});
  }
  sort((v).begin(), (v).end());
  tmp.push_back({-1, -1});
  for (long long i = 0; i < min(2 * k, (long long)v.size()); i++)
    tmp.push_back(v[i]);
  sort(tmp.begin() + 1, tmp.end(),
       [](pair<long long, long long> x, pair<long long, long long> y) {
         return x.second < y.second;
       });
  for (long long i = 0; i <= 2 * k; i++)
    for (long long j = 1; j < 2 * k; j++) dp[i][j] = 1e18;
  for (long long i = 1; i <= min(2 * k, n - 1); i++) {
    for (long long j = 1; j <= k; j++) {
      dp[i][j] = dp[i - 1][j];
      if (i > 1 and tmp[i - 1].second == tmp[i].second - 1) {
        dp[i][j] = min(dp[i][j], dp[i - 2][j - 1] + tmp[i].first);
      } else
        dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + tmp[i].first);
    }
  }
  cout << dp[min(2 * k, n - 1)][k];
}
