#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long b[500005];
long long a[500005];
multiset<pair<long long, int> > M;
multiset<pair<int, long long> > rM;
long long ans[500005];
int main() {
  cin >> k >> n;
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  sort(b + 1, b + n + 1);
  n--;
  for (int i = 1; i <= n; i++) {
    a[i] = b[i + 1] - b[i];
    M.insert(make_pair(a[i], i));
    rM.insert(make_pair(i, a[i]));
  }
  M.insert(make_pair(1e18, 0));
  M.insert(make_pair(1e18, n + 1));
  rM.insert(make_pair(0, 1e18));
  rM.insert(make_pair(n + 1, 1e18));
  ans[0] = 0;
  for (int num = 1; num <= (n + 1) / 2; num++) {
    pair<long long, int> p = *M.begin();
    ans[num] = ans[num - 1] + p.first;
    if (num == k) cout << ans[num] << endl;
    multiset<pair<int, long long> >::iterator it =
        rM.lower_bound(make_pair(p.second, -1e18));
    it--;
    pair<int, long long> a = *it;
    M.erase(M.find(make_pair(a.second, a.first)));
    rM.erase(it++);
    pair<int, long long> b = *it;
    M.erase(M.find(make_pair(b.second, b.first)));
    rM.erase(it++);
    pair<int, long long> c = *it;
    M.erase(M.find(make_pair(c.second, c.first)));
    rM.erase(it++);
    rM.insert(make_pair(b.first, a.second + c.second - b.second));
    M.insert(make_pair(a.second + c.second - b.second, b.first));
  }
}
