#include <bits/stdc++.h>
using namespace std;
template <typename T>
auto operator<<(ostream& out, T& container)
    -> decltype(container.begin(), container.end(), out) {
  bool first = true;
  out << "[";
  for (auto it = container.begin(); it != container.end(); ++it) {
    if (!first) out << ", ";
    out << *it;
    first = false;
  }
  return out << "]";
}
int k, n, m;
int t[500000];
pair<long long, int> intervals[500000];
long long dp[30000][2];
int main() {
  cin >> k >> n;
  for (int i = 0; i < n; ++i) cin >> t[i];
  sort(t, t + n);
  for (int i = 0; i < n - 1; ++i) intervals[i] = {t[i + 1] - t[i], i};
  n--;
  m = min(4 * k + 20, n);
  sort(intervals, intervals + n);
  sort(intervals, intervals + m,
       [](pair<int, int> a, pair<int, int> b) { return a.second < b.second; });
  for (int j = 0; j < m; ++j) dp[j][0] = 0;
  for (int i = 1; i <= k; ++i) {
    for (int j = 0; j < m; ++j) {
      dp[j][i % 2] = 1e18;
      if (i == 1) dp[j][i % 2] = min(dp[j][i % 2], intervals[j].first);
      if (j > 0) dp[j][i % 2] = min(dp[j][i % 2], dp[j - 1][i % 2]);
      if (j > 0 && intervals[j - 1].second != intervals[j].second - 1) {
        dp[j][i % 2] =
            min(dp[j][i % 2], intervals[j].first + dp[j - 1][(i - 1) % 2]);
      }
      if (j > 1) {
        dp[j][i % 2] =
            min(dp[j][i % 2], intervals[j].first + dp[j - 2][(i - 1) % 2]);
      }
    }
  }
  cout << dp[m - 1][k % 2] << "\n";
}
