#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
  out << "[";
  for (auto k : v) out << k << " ";
  out << "]"
      << "\n";
  return out;
}
template <class T>
ostream& operator<<(ostream& out, set<T> s) {
  out << "{";
  for (auto k : s) out << k << " ";
  out << "}"
      << "\n";
  return out;
}
template <class T, class U>
ostream& operator<<(ostream& out, pair<T, U> p) {
  out << "[ " << p.first << " , " << p.second << " ] ";
  return out;
}
template <class T, class U>
istream& operator>>(istream& in, pair<T, U>& p) {
  in >> p.first >> p.second;
  return in;
}
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  vector<pair<long long, long long> > vecs;
  long long pre = 0;
  int N, K;
  cin >> K >> N;
  vector<int> ps;
  for (int i = 0; i < int(N); i++) {
    int t;
    cin >> t;
    ps.push_back(t);
  }
  sort(ps.begin(), ps.end());
  for (int i = 0; i < int(N); i++) {
    int t = ps[i];
    if (pre) vecs.push_back({t - pre, i});
    pre = t;
  }
  sort(vecs.begin(), vecs.end());
  vector<pair<int, int> > v2;
  for (int i = 0; i < int(min(N - 1, 3 * K)); i++)
    v2.push_back({vecs[i].second, vecs[i].first});
  sort(v2.begin(), v2.end());
  vector<vector<int> > dp(v2.size() + 10, vector<int>(K + 10, long long(2e9)));
  dp[0][0] = 0;
  v2.push_back({1e9, 1e9});
  for (int i = 0; i < int(v2.size() - 1); i++) {
    for (int j = 0; j < int(K); j++) {
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
      if (v2[i].first + 1 == v2[i + 1].first) {
        dp[i + 2][j + 1] = min(dp[i + 2][j + 1], dp[i][j] + v2[i].second);
      } else
        dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + v2[i].second);
    }
  }
  int res = dp[0][K];
  for (int j = 0; j < int(dp.size()); j++) res = min(res, dp[j][K]);
  cout << res << "\n";
  return 0;
}
