#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 5;
const int MAXK = 5005;
const int MAXD = 2 * MAXK + 5;
const int INF = 1e9 + 5;
int dp[MAXK][2][2];
pair<int, int> gaps[MAXN];
int main() {
  int n, k;
  scanf("%d %d", &k, &n);
  for (int i = 0; i < int(n); i++) scanf("%d", &gaps[i].first);
  sort(gaps, gaps + n);
  for (int i = int(1); i < int(n); i++)
    gaps[i - 1] = {gaps[i].first - gaps[i - 1].first, i - 1};
  sort(gaps, gaps + (n - 1));
  int bstTop = 2 * k + 5;
  sort(gaps, gaps + (min(n - 1, bstTop)),
       [](const pair<int, int> &a, const pair<int, int> &b) {
         return a.second < b.second;
       });
  for (int i = 0; i < int(2); i++)
    for (int j = 0; j < int(MAXK); j++) dp[j][i][0] = dp[j][i][1] = INF;
  dp[0][0][0] = 0;
  dp[1][0][1] = gaps[0].first;
  int ind = 1, rta = INF;
  if (k == 1) rta = min(rta, gaps[0].first);
  for (int i = int(1); i < int(min(bstTop, n - 1)); i++) {
    for (int j = 0; j < int(MAXK); j++) dp[j][ind][0] = dp[j][ind][1] = INF;
    for (int j = 0; j < int(k + 1); j++) {
      dp[j][ind][0] = min(
          {dp[j][ind][0], dp[j][(ind + 1) & 1][0], dp[j][(ind + 1) & 1][1]});
      if (j)
        dp[j][ind][1] =
            min(dp[j][ind][1], dp[j - 1][(ind + 1) & 1][0] + gaps[i].first);
      if (abs(gaps[i].second - gaps[i - 1].second) > 1 && j)
        dp[j][ind][1] =
            min(dp[j][ind][1], dp[j - 1][(ind + 1) & 1][1] + gaps[i].first);
      if (j == k) rta = min({rta, dp[j][ind][0], dp[j][ind][1]});
    }
    ind = (ind + 1) & 1;
  }
  printf("%d", rta);
  return 0;
}
