#include <bits/stdc++.h>
using namespace std;
int main(void) {
  vector<long long> help;
  vector<pair<long long, int>> result;
  int K, N, i, j;
  long long t1, t2;
  cin >> K >> N;
  for (i = 1; i <= N; i++) {
    cin >> t1;
    help.push_back(t1);
  }
  sort(help.begin(), help.end());
  for (i = 1; i <= N - 1; i++) {
    result.push_back(pair<long long, int>(help[i] - help[i - 1], i));
  }
  sort(result.begin(), result.end());
  long long Q[5001][3];
  memset(Q, 0x3f3f3f3f, sizeof(Q));
  Q[0][2] = Q[0][1] = Q[0][0] = 0;
  Q[1][1] = result[0].first;
  for (i = 2; i < N && i <= 3 * K; i++) {
    int col = i % 3;
    for (j = K; j > 0; j--) {
      if (abs(result[i - 1].second - result[i - 2].second) == 1) {
        Q[j][col] = min(Q[j][(col + 2) % 3],
                        Q[j - 1][(col + 1) % 3] + result[i - 1].first);
      } else {
        Q[j][col] = min(Q[j][(col + 2) % 3],
                        Q[j - 1][(col + 2) % 3] + result[i - 1].first);
      }
    }
  }
  cout << Q[K][(i - 1) % 3] << endl;
  return 0;
}
