#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using pii = pair<int, int>;
int t[5010];
int dp[3][5010];
pii v[4 * 5010];
vector<int> diffs;
int main() {
  ios_base::sync_with_stdio(false);
  int i, j, n, k, l0, l1, l2;
  cin >> k >> n;
  for (i = 1; i <= n; ++i) cin >> t[i];
  sort(t + 1, t + n + 1);
  for (i = 1; i < n; ++i) {
    v[i] = {t[i], t[i + 1]};
  }
  sort(v + 1, v + n,
       [](pii a, pii b) { return a.second - a.first < b.second - b.first; });
  n = min(n - 1, 4 * k);
  sort(v + 1, v + n + 1, [](pii a, pii b) { return a.first < b.first; });
  dp[0][0] = 0;
  for (j = 1; j <= k; ++j) dp[0][j] = 2000000010;
  for (l0 = 2, l1 = 0, l2 = 1, i = 1; i <= n; ++i) {
    for (j = 0; j <= k; ++j) {
      dp[l2][j] = dp[l1][j];
      if (i > 1 && v[i - 1].second == v[i].first) {
        dp[l2][j] = min(dp[l2][j], dp[l0][j - 1] + v[i].second - v[i].first);
      } else {
        dp[l2][j] = min(dp[l2][j], dp[l1][j - 1] + v[i].second - v[i].first);
      }
    }
    l0 = (l0 == 2 ? 0 : l0 + 1);
    l1 = (l1 == 2 ? 0 : l1 + 1);
    l2 = (l2 == 2 ? 0 : l2 + 1);
  }
  cout << dp[l1][k] << '\n';
  return 0;
}
