#include <bits/stdc++.h>
using namespace std;
int v[500100];
map<int, vector<pair<int, int> > > Map;
set<pair<int, int> > Set;
bool Overlap(int l, int r) {
  auto it = Set.lower_bound({l, -1});
  if (it != Set.end()) {
    if (it->second <= r) return 0;
  }
  Set.insert({r, l});
  return 1;
}
int main() {
  int n, k;
  cin >> k >> n;
  for (int i = 0; i < n; ++i) cin >> v[i];
  sort(v, v + n);
  for (int i = 0; i + 1 < n; ++i)
    Map[v[i + 1] - v[i]].push_back({v[i + 1], v[i]});
  int Ans = 0;
  for (auto it1 : Map) {
    for (auto it2 : it1.second) {
      if (!k) break;
      if (Overlap(it2.second, it2.first)) {
        --k;
        Ans += it1.first;
      }
    }
    if (!k) break;
  }
  cout << Ans << endl;
  return 0;
}
