#include <bits/stdc++.h>
using namespace std;
const int MAX = 5e5 + 5;
int k, n, a[MAX];
multiset<pair<long long, int> > s_val;
multiset<pair<int, long long> > s_pos;
int main() {
  scanf("%d%d", &k, &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i < n; i++) {
    s_pos.insert({i, a[i + 1] - a[i]});
    s_val.insert({a[i + 1] - a[i], i});
  }
  long long ans = 0;
  while (k > 0) {
    long long val = s_val.begin()->first;
    int pos = s_val.begin()->second;
    s_val.erase(s_val.begin());
    ans += val;
    long long sum = -val;
    auto l = s_pos.lower_bound({pos, LLONG_MIN});
    assert(l != s_pos.end());
    int id = pos, has = 0;
    if (l != s_pos.begin()) {
      has++;
      l--;
      s_val.erase(s_val.find({l->second, l->first}));
      sum += l->second;
      id = min(id, l->first);
      l++;
    }
    l++;
    if (l != s_pos.end()) {
      has++;
      s_val.erase(s_val.find({l->second, l->first}));
      sum += l->second;
      id = min(id, l->first);
      l--;
    }
    auto it = s_pos.lower_bound({pos, LLONG_MIN});
    if (it != s_pos.begin()) {
      it--;
      s_pos.erase(it);
    }
    it = s_pos.lower_bound({pos, LLONG_MIN});
    s_pos.erase(it);
    it = s_pos.lower_bound({pos, LLONG_MIN});
    if (it != s_pos.end()) s_pos.erase(it);
    if (has == 2) {
      s_pos.insert({id, sum});
      s_val.insert({sum, id});
    }
    k--;
  }
  printf("%lld\n", ans);
  return 0;
}
