#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll inf = 1e18;
int main() {
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(begin(a), end(a));
  set<pair<ll, ll>> index_value, value_index;
  for (int i = 0; i + 1 < n; ++i) {
    index_value.emplace(i, a[i + 1] - a[i]);
    value_index.emplace(a[i + 1] - a[i], i);
  }
  index_value.emplace(-1, inf);
  index_value.emplace(n, inf);
  value_index.emplace(inf, -1);
  value_index.emplace(inf, n);
  ll res = 0;
  for (int lp = 0; lp < k; ++lp) {
    int v, l, r;
    ll val, lval, rval;
    tie(val, v) = *begin(value_index);
    auto it = index_value.lower_bound(make_pair(v, val));
    tie(l, lval) = *prev(it);
    tie(r, rval) = *next(it);
    index_value.erase(make_pair(v, val));
    index_value.erase(make_pair(l, lval));
    index_value.erase(make_pair(r, rval));
    value_index.erase(make_pair(val, v));
    value_index.erase(make_pair(lval, l));
    value_index.erase(make_pair(rval, r));
    index_value.emplace(v, lval + rval - val);
    value_index.emplace(lval + rval - val, v);
    res += val;
  }
  cout << res << endl;
}
