#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000001;
const long long INF = 2e18;
const long long MOD = 1000000007;
const double pi = 3.14159265358979323846;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int main() {
  int k, n;
  cin >> k >> n;
  vector<int> t(n);
  for (int i = 0; i < (int)(n); i++) {
    cin >> t[i];
  }
  sort(t.begin(), t.end());
  vector<pair<int, int> > aida(n - 1);
  for (int i = 1; i <= (int)(n - 1); i++) {
    aida[i - 1].first = t[i] - t[i - 1];
    aida[i - 1].second = i;
  }
  sort(aida.begin(), aida.end());
  vector<bool> used(n - 1, true);
  for (int i = 15000; i < aida.size(); i++) {
    used[aida[i].second] = false;
  }
  vector<pair<int, int> > aida2;
  for (int i = 0; i < (int)(n - 1); i++) {
    if (used[i]) {
      aida2.push_back(pair<int, int>(t[i + 1] - t[i], false));
      if (i != n - 2 && !used[i + 1]) {
        aida2.back().second = true;
      }
    }
  }
  vector<vector<vector<long long> > > dp(
      aida2.size() + 1,
      vector<vector<long long> >(k + 1, vector<long long>(2, INF)));
  dp[0][0][1] = 0;
  for (int i = 0; i < (int)(aida2.size()); i++) {
    for (int j = 0; j < (int)(k); j++) {
      for (int l = 0; l < (int)(2); l++) {
        if (l == 0) {
          dp[i + 1][j][1] = min(dp[i + 1][j][1], dp[i][j][l]);
        } else {
          dp[i + 1][j][1] = min(dp[i + 1][j][1], dp[i][j][l]);
          if (aida2[i].second) {
            dp[i + 1][j + 1][1] =
                min(dp[i + 1][j + 1][1], dp[i][j][l] + aida[i].first);
          } else {
            dp[i + 1][j + 1][0] =
                min(dp[i + 1][j + 1][0], dp[i][j][l] + aida[i].first);
          }
        }
      }
    }
  }
  long long ans = INF;
  for (int i = 0; i < (int)(aida2.size() + 1); i++) {
    ans = min(ans, min(dp[i][k][0], dp[i][k][1]));
  }
  cout << ans << endl;
}
