#include <bits/stdc++.h>
const int N = 100001;
using namespace std;
bool f(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> k >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  pair<int, int> b[n - 1];
  for (int i = 0; i < n - 1; i++) b[i] = make_pair(a[i + 1] - a[i], i);
  sort(b, b + n - 1);
  if (k == 1) {
    cout << b[0].first;
    return 0;
  }
  int len = 2 * k - 1;
  pair<int, int> c[len];
  copy(b, b + len, c);
  sort(c, c + len, f);
  long long int last[k + 1], fir[k + 1];
  last[0] = 0;
  last[1] = c[len - 1].first;
  for (int i = 2; i < k + 1; i++) last[i] = 1e13;
  fir[0] = 0;
  fir[1] = min(c[len - 2].first, c[len - 1].first);
  for (int i = 2; i < k + 1; i++) fir[i] = 1e13;
  for (int i = len - 3; i >= 0; i--) {
    long long int h[k + 1];
    h[0] = 0;
    for (int j = 1; j < k + 1; j++) {
      h[j] = c[i].first +
             (c[i + 1].second - c[i].second > 1 ? fir[j - 1] : last[j - 1]);
      h[j] = min(h[j], fir[j]);
    }
    copy(fir, fir + k + 1, last);
    copy(h, h + k + 1, fir);
  }
  cout << fir[k];
}
