#include <bits/stdc++.h>
using namespace std;
const long long int MAX = 500000;
const long long int inf = 1e18;
bool ok[MAX + 1] = {false};
long long int dp[5001][2] = {0};
bool vis[5001][2] = {false};
void solve() {
  long long int k, n;
  cin >> k >> n;
  vector<long long int> v(n + 1, 0);
  for (long long int j = 1; j <= n; j++) {
    cin >> v[j];
  }
  sort(v.begin(), v.end());
  vector<pair<long long int, long long int>> p;
  for (long long int j = 0; j < n; j++) {
    p.push_back({v[j + 1] - v[j], j});
  }
  sort(p.begin(), p.end());
  for (long long int j = 0; j < min(3 * k, n); j++) {
    ok[p[j].second] = true;
  }
  for (long long int j = n - 1; j >= 1; j--) {
    if (ok[j]) {
      for (long long int i = k; i >= 1; i--) {
        if (vis[i][0] && vis[i][1]) {
          vis[i][0] = true;
          dp[i][0] = min(dp[i][0], dp[i][1]);
        } else {
          if (vis[i][1]) {
            vis[i][0] = true;
            dp[i][0] = dp[i][1];
          }
        }
        if (vis[i - 1][0]) {
          vis[i][1] = true;
          dp[i][1] = dp[i - 1][0] + v[j + 1] - v[j];
        }
      }
      if (vis[1][1]) {
        dp[1][1] = min(dp[1][1], v[j + 1] - v[j]);
      } else {
        vis[1][1] = true;
        dp[1][1] = v[j + 1] - v[j];
      }
    }
  }
  if (vis[k][0] && vis[k][1]) {
    cout << min(dp[k][0], dp[k][1]) << "\n";
  } else if (vis[k][0]) {
    cout << dp[k][0] << "\n";
  } else if (vis[k][1]) {
    cout << dp[k][1] << "\n";
  }
  return;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
