#include <bits/stdc++.h>
using namespace std;
template <class T>
void splitstr(const string &s, vector<T> &out) {
  istringstream in(s);
  out.clear();
  copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
static void redirect(int argc, const char **argv) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  if (argc > 1) {
    static filebuf f;
    f.open(argv[1], ios::in);
    cin.rdbuf(&f);
    if (!cin) {
      cerr << "Failed to open '" << argv[1] << "'" << endl;
      exit(1);
    }
  }
  if (argc > 2) {
    static filebuf f;
    f.open(argv[2], ios::out | ios::trunc);
    cout.rdbuf(&f);
    if (!cout) {
      cerr << "Failed to open '" << argv[2] << "'" << endl;
    }
  }
}
int main(int argc, const char **argv) {
  redirect(argc, argv);
  int K, N;
  cin >> K >> N;
  vector<int> t(N);
  for (int i = 0; i < N; i++) cin >> t[i];
  sort(begin(t), end(t));
  vector<pair<int, int> > tt(N - 1);
  for (int i = 0; i < N - 1; i++) tt[i] = pair<int, int>(t[i], t[i + 1]);
  sort(begin(tt), end(tt),
       [](const pair<int, int> &a, const pair<int, int> &b) {
         return a.second - a.first < b.second - b.first;
       });
  if (3 * K < N) tt.resize(3 * K);
  sort(begin(tt), end(tt));
  vector<int> dp(K + 1, INT_MAX / 2);
  dp[0] = 0;
  vector<int> dpp(K + 1, INT_MAX / 2);
  for (int i = 1; i <= ((long long)(tt).size()); i++) {
    int d = tt[i - 1].second - tt[i - 1].first;
    bool p = (i == 1 || tt[i - 2].second < tt[i - 1].first);
    vector<int> dp2 = dp;
    for (int j = K; j > 0; j--)
      dp2[j] = min(dp2[j], (p ? dp[j - 1] : dpp[j - 1]) + d);
    dpp = move(dp);
    dp = move(dp2);
  }
  cout << dp[K] << '\n';
  return 0;
}
