#include <bits/stdc++.h>
using namespace std;
int t[500010];
int a[500010];
int par[500010];
int l[500010], r[500010];
long long val[500010];
int root(int x) {
  if (par[x] == x) return par[x];
  return par[x] = root(par[x]);
}
void join(int x, int y) {
  x = root(x);
  y = root(y);
  if (x != y) {
    par[x] = y;
    l[y] = min(l[y], l[x]);
    r[y] = max(r[y], r[x]);
  }
}
int main(int argc, char const *argv[]) {
  int n, k;
  scanf("%d %d", &k, &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &t[i]);
  }
  sort(t + 1, t + n + 1);
  for (int i = 1; i < n; i++) {
    a[i] = t[i + 1] - t[i];
  }
  n--;
  long long ans = 0;
  set<pair<long long, int> > s;
  int begin = 1;
  int end = n;
  for (int i = 1; i <= n; i++) {
    par[i] = i;
    l[i] = r[i] = i;
    val[i] = a[i];
    s.insert(pair<long long, int>(a[i], i));
  }
  for (int i = 0; i < k; i++) {
    if (s.empty()) break;
    pair<long long, int> p = *s.begin();
    s.erase(p);
    long long cost = p.first;
    int pos = p.second;
    ans += cost;
    if (l[pos] == begin && r[pos] == end) break;
    if (l[pos] == begin) {
      int nxt = root(r[pos] + 1);
      s.erase(pair<long long, int>(val[nxt], nxt));
      begin = r[nxt] + 1;
    } else if (r[pos] == end) {
      int prev = root(l[pos] - 1);
      s.erase(pair<long long, int>(val[prev], prev));
      end = l[prev] - 1;
    } else {
      int nxt = root(r[pos] + 1);
      int prev = root(l[pos] - 1);
      long long P = val[prev];
      long long Q = val[nxt];
      join(nxt, pos);
      join(pos, prev);
      s.erase(pair<long long, int>(P, prev));
      s.erase(pair<long long, int>(Q, nxt));
      s.insert(pair<long long, int>(P + Q - cost, root(pos)));
      val[root(pos)] = P + Q - cost;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
