#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10, N2 = 5e3 + 10;
vector<int> fpts, pts;
int a[N], n, k, dp[N2 * 2][N2], fsz;
bool check(int mlen) {
  pts.clear();
  for (int i = 1; i < n; i++) {
    if (a[i] - a[i - 1] <= mlen) {
      pts.push_back(a[i]);
      pts.push_back(a[i - 1]);
    }
  }
  sort(pts.begin(), pts.end());
  pts.erase(unique(pts.begin(), pts.end()), pts.end());
  if (pts.size() >= k * 2) return true;
  return false;
}
int sz;
vector<pair<int, int> > vc;
int calc(int i, int cnt) {
  if (cnt == k) return 0;
  if (i == sz) return 1e9;
  int &ret = dp[i][cnt];
  if (ret != -1) return ret;
  ret = calc(i + 1, cnt);
  bool ok = (i != sz - 1 && vc[i].first + 1 == vc[i + 1].first);
  ret = min(ret, vc[i].second + calc(i + 1 + ok, cnt + 1));
  return ret;
}
int main() {
  scanf("%d%d", &k, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  sort(a, a + n);
  for (int i = 1; i < n; i++) {
    int len = a[i] - a[i - 1];
    vc.push_back(make_pair(len, i - 1));
  }
  sort(vc.begin(), vc.end());
  vc.resize(min((int)vc.size(), 2 * k + 5));
  for (int i = 0; i < vc.size(); i++) swap(vc[i].first, vc[i].second);
  sort(vc.begin(), vc.end());
  sz = vc.size();
  memset(dp, -1, sizeof dp);
  cout << calc(0, 0) << endl;
  return 0;
}
