#include <bits/stdc++.h>
using namespace std;
long long int pow_mod(long long int a, long long int b) {
  long long int res = 1;
  while (b != 0) {
    if (b & 1) {
      res = (res * a) % 1000000007;
    }
    a = (a * a) % 1000000007;
    b /= 2;
  }
  return res;
}
void solve() {
  long long int k, n;
  cin >> k >> n;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  if (!a.empty()) sort(a.begin(), a.end());
  long long int lim = 3 * k;
  vector<long long int> dif;
  for (long long int i = 1; i < n; i++) {
    if (a[i] != a[i - 1]) dif.push_back(a[i] - a[i - 1]);
  }
  if (!dif.empty()) sort(dif.begin(), dif.end());
  lim = min(lim, (long long int)dif.size());
  long long int dp[lim + 1][k + 1][2];
  for (long long int i = 0; i <= lim; i++) {
    for (long long int j = 0; j <= k; j++) {
      dp[i][j][1] = dp[i][j][0] = (long long int)1e18;
      if (j == 0) dp[i][j][0] = 0;
    }
  }
  for (long long int i = 0; i < lim; i++) {
    for (long long int j = 1; j <= k; j++) {
      long long int id = i + 1;
      dp[id][j][0] = min(dp[id - 1][j][0], dp[id - 1][j][1]);
      dp[id][j][1] = dif[i] + dp[id - 1][j - 1][0];
    }
  }
  long long int ans = 0;
  ans = dp[lim][k][0];
  ans = min(ans, dp[lim][k][1]);
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  t = 1;
  while (t--) solve();
  return 0;
}
