#include <bits/stdc++.h>
using namespace std;
struct miStruct {
  int val, a;
};
bool operator<(const miStruct &a, const miStruct &b) { return (a.val < b.val); }
int K, N;
int calcular(vector<miStruct> &v) {
  for (int i = 0; i < v.size(); i++) swap(v[i].val, v[i].a);
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) swap(v[i].val, v[i].a);
  vector<vector<int> > DP(v.size(), vector<int>(K + 1, (1e9)));
  for (int i = 0; i < v.size(); i++) DP[i][0] = 0;
  DP[0][1] = v[0].val;
  if (v.size() > 1) {
    DP[1][1] = min(v[0].val, v[1].val);
    if (K > 1 && v[0].a + 1 != v[1].a) DP[1][2] = v[0].val + v[1].val;
  }
  for (int i = 2; i < v.size(); i++) {
    for (int j = 1; j <= K; j++) {
      DP[i][j] = min(DP[i][j], DP[i - 1][j]);
      if (v[i - 1].a + 1 != v[i].a)
        DP[i][j] = min(DP[i][j], DP[i - 1][j - 1] + v[i].val);
      DP[i][j] = min(DP[i][j], DP[i - 2][j - 1] + v[i].val);
    }
  }
  return DP.back().back();
}
int main() {
  scanf("%d %d", &K, &N);
  vector<int> v(N);
  for (int i = 0; i < N; i++) scanf("%d", &v[i]);
  sort(v.begin(), v.end());
  vector<miStruct> d(N - 1);
  for (int i = 1; i < N; i++) d[i - 1] = {v[i] - v[i - 1], i - 1};
  sort(d.begin(), d.end());
  if (2 * K + 10 < d.size()) d.resize(2 * K + 10);
  printf("%d\n", calcular(d));
  return 0;
}
