#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> k >> n;
  vector<int> times(n, 0);
  for (int i = 0; i < n; ++i) cin >> times[i];
  sort(times.begin(), times.end());
  for (int i = 0; i < times.size() - 1; ++i) times[i] = times[i + 1] - times[i];
  times.pop_back();
  vector<int> prev_prev(k + 1, 0), prev(k + 1, 0);
  prev_prev[1] = times[0];
  prev[1] = times[1];
  int ans = (k == 1 ? min(prev_prev[1], prev[1]) : INT32_MAX);
  for (int i = 2; i < n - 1; ++i) {
    vector<int> curr(k + 1, 0);
    for (int j = 1; j <= k; ++j)
      if (prev[j] != 0 || prev_prev[j - 1] != 0)
        curr[j] = min(
            (prev[j] == 0 ? INT32_MAX : prev[j]),
            (prev_prev[j - 1] == 0 ? INT32_MAX - times[i] : prev_prev[j - 1]) +
                times[i]);
    if (curr[k] > 0) ans = min(ans, curr[k]);
    prev_prev = prev;
    prev = curr;
  }
  cout << ans;
}
