#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5, oo = 1e9;
int n, k, f[5005 * 2][5005], res = oo;
struct school {
  int val;
  int vt;
} t[N];
bool fun1(school x1, school x2) {
  return (x1.val < x2.val || (x1.val == x2.val && x1.vt < x2.vt));
}
bool fun2(school x1, school x2) { return (x1.vt < x2.vt); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> k >> n;
  for (int i = 1; i <= n; i++) cin >> t[i].val;
  sort(t + 1, t + 1 + n, fun1);
  for (int i = n; i >= 2; i--) {
    t[i].val = t[i].val - t[i - 1].val;
    t[i].vt = i;
  }
  for (int i = 1; i <= n - 1; i++) {
    t[i].val = t[i + 1].val;
    t[i].vt = t[i + 1].vt;
  }
  n--;
  sort(t + 1, t + 1 + n, fun1);
  n = min(n, 2 * k);
  sort(t + 1, t + 1 + n, fun2);
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= k; j++) f[i][j] = oo;
  f[1][1] = t[1].val;
  for (int i = 2; i <= n; i++) {
    f[i][1] = t[i].val;
    if (t[i - 1].vt == t[i].vt - 1)
      for (int j = 2; j <= k; j++)
        f[i][j] = min(f[i - 1][j], f[i - 2][j - 1] + t[i].val);
    else
      for (int j = 2; j <= k; j++)
        f[i][j] = min(f[i - 1][j], f[i - 1][j - 1] + t[i].val);
    res = min(res, f[i][k]);
  }
  cout << res;
  return 0;
}
