#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > dp(3, vector<int>(5001, 1000000000));
vector<int> T(500000);
vector<int> D(500000);
int main() {
  int K, N;
  scanf("%d%d", &K, &N);
  for (int n = 0; n < N; ++n) {
    scanf("%d", &T[n]);
  }
  sort(T.begin(), T.begin() + N);
  for (int n = 1; n < N; ++n) {
    D[n - 1] = T[n] - T[n - 1];
  }
  if (N == 2) {
    printf("%d", D[0]);
    return 0;
  }
  vector<pair<int, int> > Di(N - 1);
  for (int i = 0; i < N - 1; ++i) {
    Di[i] = pair<int, int>(D[i], i);
  }
  sort(Di.begin(), Di.end());
  vector<int> minv;
  minv.reserve(15000);
  for (int i = 0; i < min(3 * K, N - 1); ++i) {
    minv.push_back(Di[i].second);
  }
  sort(minv.begin(), minv.end());
  dp[0][0] = dp[1][0] = dp[2][0] = 0;
  dp[0][1] = D[minv[0]];
  dp[1][1] = min(D[minv[0]], D[minv[1]]);
  if (minv[0] + 1 != minv[1]) {
    dp[1][2] = D[minv[0]] + D[minv[1]];
  }
  for (unsigned at = 2; at < minv.size(); ++at) {
    const int i = minv[at];
    const int previ = minv[at - 1];
    if (previ + 1 != i) {
      for (int k = 1; k <= K; ++k) {
        dp[at % 3][k] = min(dp[at % 3][k], dp[(at - 1) % 3][k - 1] + D[i]);
      }
    } else {
      for (int k = 1; k <= K; ++k) {
        dp[at % 3][k] = min(dp[at % 3][k], dp[(at - 2) % 3][k - 1] + D[i]);
      }
    }
    for (int k = 1; k <= K; ++k) {
      dp[at % 3][k] = min(dp[at % 3][k], dp[(at - 1) % 3][k]);
    }
  }
  printf("%d", dp[(minv.size() - 1) % 3][K]);
  return 0;
}
