#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
using namespace std;
const int inf = 1e9;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int k, n;
  cin >> k >> n;
  vector<int> a(n), tp;
  vector<pair<int, int>> p(n - 1);
  for (auto &e : a) cin >> e;
  sort(a.begin(), a.end());
  for (int i = 0; i + 1 < n; i++) p[i] = {a[i + 1] - a[i], i};
  sort(p.begin(), p.end());
  int ts = min(n - 1, k * 3);
  for (int i = 0; i < ts; i++) tp.push_back(p[i].second);
  sort(tp.begin(), tp.end());
  vector<vector<int>> dp(k + 1, vector<int>(2, inf));
  vector<vector<int>> ndp(k + 1, vector<int>(2, inf));
  dp[k][0] = 0;
  dp[k - 1][1] = a[tp[0] + 1] - a[tp[0]];
  for (int i = 1; i < ts; i++) {
    for (int i = 0; i <= k; i++) ndp[i][0] = ndp[i][1] = inf;
    for (int j = k; j >= 0; j--) {
      ndp[j][0] = min(dp[j][0], ndp[j][0]);
      ndp[j][0] = min(dp[j][1], ndp[j][0]);
      if (j == k) continue;
      ndp[j][1] = min(ndp[j][1], dp[j + 1][0] + a[tp[i] + 1] - a[tp[i]]);
      if (tp[i - 1] + 1 != tp[i])
        ndp[j][1] = min(ndp[j][1], dp[j + 1][1] + a[tp[i] + 1] - a[tp[i]]);
    }
    swap(ndp, dp);
  }
  cout << min(dp[0][0], dp[0][1]);
  cin >> n;
}
