#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, p;
  cin >> k >> n;
  std::vector<long> v(n, 0);
  for (int i = 0; i < n; ++i) cin >> v[i];
  sort(v.begin(), v.end());
  std::vector<std::vector<pair<long, long> > > dp(
      n, std::vector<pair<long, long> >(k + 1,
                                        make_pair(100000000001, 100000000001)));
  dp[0][1].first = 1000000001;
  dp[0][1].second = 1000000001;
  dp[1][1].first = v[1] - v[0];
  dp[1][1].second = 1000000001;
  for (int i = 2; i < n; ++i) {
    dp[i][1].first = v[i] - v[i - 1];
    dp[i][1].second = min(dp[i - 1][1].first, dp[i - 1][1].first);
  }
  for (int i = 2; i <= k; ++i) {
    for (int id = 2; id < n; ++id) {
      dp[id][i].first = min(dp[id - 2][i - 1].first, dp[id - 2][i - 1].second) +
                        v[id] - v[id - 1];
      dp[id][i].second = min(dp[id - 1][i].first, dp[id - 1][i].second);
    }
  }
  cout << min(dp[n - 1][k].first, dp[n - 1][k].second);
  return 0;
}
