#include <bits/stdc++.h>
using namespace std;
struct __s {
  __s() {
    if (1) {
      ios_base::Init i;
      cin.sync_with_stdio(0);
      cin.tie(0);
    }
  }
  ~__s() {
    if (!1)
      fprintf(stderr, "Execution time: %.3lf s.\n",
              (double)clock() / CLOCKS_PER_SEC);
    int n;
    cin >> n;
  }
} __S;
int a[511111];
pair<int, int> dp[2][20011];
int main(void) {
  int k, n;
  cin >> k >> n;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  vector<pair<int, int> > v;
  for (int i = 0; i < (int)(n - 1); i++) {
    v.push_back(make_pair(a[i + 1] - a[i], i));
  }
  sort(v.begin(), v.end());
  while (v.size() > min(4 * k, n)) v.pop_back();
  for (int i = 0; i < (int)(v.size()); i++) {
    swap(v[i].first, v[i].second);
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < (int)(v.size()); i++) {
    swap(v[i].first, v[i].second);
  }
  dp[0][0] = v[0];
  for (int j = 1; j < v.size(); j++) {
    dp[0][j] = min(dp[0][j - 1], v[j]);
  }
  for (int I = 1, i = 1; I < k; I++, i = !i) {
    for (int j = 0; j < (int)(v.size()); j++) {
      dp[i][j] = make_pair(2e9, 0);
    }
    for (int j = 1; j < v.size(); j++) {
      int k = j - 1;
      while (k >= 0 && abs(dp[!i][k].second - v[j].second) <= 1) k--;
      if (k < 0) continue;
      dp[i][j] = min(dp[i][j - 1],
                     make_pair(dp[!i][k].first + v[j].first, v[j].second));
    }
  }
  cout << dp[!(k % 2)][v.size() - 1].first << '\n';
  return 0;
}
