#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MAXN = 1e5 + 5;
const long long LINF = 1e18;
const double pi = 3.1415926535;
const double EPS = 1e-9;
int main() {
  int k, n;
  scanf("%d %d", &k, &n);
  vector<int> a(n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a.begin(), a.end());
  map<int, int> mp;
  for (int i = 0; i < n - 1; i++) mp[i] = a[i + 1] - a[i];
  mp[-1] = INF;
  mp[INF] = INF;
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      pq;
  for (int i = 0; i < n - 1; i++) pq.push(pair<int, int>(mp[i], i));
  int ans = 0;
  while (k) {
    int x = pq.top().first;
    int i = pq.top().second;
    pq.pop();
    if (mp.count(i) == 0) continue;
    if (mp[i] != x) continue;
    ans += x;
    int nx = -x;
    {
      auto it = mp.find(i);
      --it;
      nx += it->second;
      mp.erase(it);
    }
    {
      auto it = mp.find(i);
      ++it;
      nx += it->second;
      mp.erase(it);
    }
    mp[i] = nx;
    pq.push(pair<int, int>(nx, i));
    k--;
  }
  printf("%d\n", ans);
  return 0;
}
