#include <bits/stdc++.h>
using namespace std;
int n, k, dp[4][5010], t[500010], d[500010], p;
pair<int, int> par[500010];
bool boo[500010];
int main() {
  cin >> k >> n;
  for (int i = 1; i <= n; ++i) cin >> t[i];
  sort(t + 1, t + n + 1);
  for (int i = 1; i < n; ++i) {
    d[i] = par[i].first = t[i + 1] - t[i];
    par[i].second = i;
  }
  sort(par + 1, par + n);
  for (int i = 1; i <= min(n, 3 * k); ++i) boo[par[i].second] = 1;
  memset(dp, 0x3f, sizeof(dp));
  for (int i = 0; i < 4; dp[i++][0] = 0)
    ;
  for (int i = 1; i < n; ++i) {
    if (!boo[i]) continue;
    p++;
    for (int j = 1; j <= min(p, k); ++j) {
      dp[p & 3][j] =
          min(dp[(p - 1) & 3][j], dp[(p - 1 - boo[i - 1]) & 3][j - 1] + d[i]);
    }
  }
  cout << dp[p & 3][k] << endl;
  return 0;
}
