#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007LL;
long long large = 2000000000000000000LL;
int main() {
  int k, n;
  cin >> k >> n;
  vector<int> t(n, 0);
  for (int i = 0; i < n; i++) cin >> t[i];
  sort(t.begin(), t.end());
  vector<pair<int, int> > e;
  for (int i = 1; i < (int)t.size(); i++) {
    e.push_back(pair<int, int>(t[i] - t[i - 1], t[i - 1]));
  }
  sort(e.begin(), e.end());
  while (e.size() > 40000) e.pop_back();
  for (int i = 0; i < (int)e.size(); i++) {
    swap(e[i].first, e[i].second);
  }
  sort(e.begin(), e.end());
  int sz = (int)e.size();
  vector<int> dp(sz, 1000000000);
  for (int j = 1; j <= k; j++) {
    vector<int> dp1(sz, 1000000000);
    if (j == 1) {
      for (int i = 0; i < sz; i++) {
        dp1[i] = e[i].second;
        if (i) dp1[i] = min(dp1[i], dp1[i - 1]);
      }
      dp = dp1;
    } else {
      for (int i = 0; i < sz; i++) {
        if (i >= 2) {
          dp1[i] = min(dp1[i], dp[i - 2] + e[i].second);
        }
        if (i) {
          dp1[i] = min(dp1[i], dp1[i - 1]);
          if (e[i].first > e[i - 1].first + e[i - 1].second) {
            dp1[i] = min(dp1[i], dp[i - 1] + e[i].second);
          }
        }
      }
      dp = dp1;
    }
  }
  cout << dp.back() << endl;
  return 0;
}
