#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[(int)(N2 * 2.5)][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.5) return true;
  return false;
}
int calc(int ind, int cnt) {
  if (cnt == k) return 0;
  if (ind > fsz - 1) return 1e9 + 10;
  if (dp[ind][cnt] != -1) return dp[ind][cnt];
  int res = calc(ind + 1, cnt);
  return dp[ind][cnt] =
             min(res, (fpts[ind] - fpts[ind - 1]) + calc(ind + 2, cnt + 1));
}
int main() {
  memset(dp, -1, sizeof dp);
  scanf("%d%d", &k, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  sort(a, a + n);
  int l = 1, r = 1e9 + 10;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      fpts = pts;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  int sz = fpts.size();
  while (sz > k * 2.5) {
    fpts.pop_back();
    sz--;
  }
  fsz = fpts.size();
  cout << calc(1, 0);
  return 0;
}
