#include <bits/stdc++.h>
using namespace std;
struct node {
  long long a, b;
  node() {}
  node(long long _1, long long _2) {
    a = _1;
    b = _2;
  }
  bool operator<(const node& X) const { return a > X.a; }
};
priority_queue<node> Q;
long long Nxt[500010], Pre[500010], V[500010], K, n;
bool invalid[500010];
int main() {
  scanf("%lld%lld", &K, &n);
  for (long long i = 1; i <= n; i++) scanf("%lld", &V[i]);
  sort(V + 1, V + n + 1);
  for (long long i = 1; i < n; i++) V[i] = V[i + 1] - V[i];
  V[n] = 0;
  n--;
  V[0] = 1e18, V[n + 1] = 1e18;
  for (long long i = 0; i <= n; i++) Nxt[i] = i + 1;
  for (long long i = n + 1; i > 0; i--) Pre[i] = i - 1;
  for (long long i = 1; i <= n; i++) Q.push(node(V[i], i));
  long long ans = 0;
  while (K--) {
    node tmp = Q.top();
    while (invalid[tmp.b]) Q.pop(), tmp = Q.top();
    Q.pop();
    ans += tmp.a;
    long long p = Pre[tmp.b], s = Nxt[tmp.b];
    V[tmp.b] = V[p] + V[s] - V[tmp.b];
    invalid[p] = 1;
    invalid[s] = 1;
    Nxt[p] = Nxt[tmp.b];
    Pre[s] = Pre[tmp.b];
    Pre[tmp.b] = Pre[p];
    Nxt[tmp.b] = Nxt[s];
    Q.push(node(V[tmp.b], tmp.b));
  }
  printf("%lld\n", ans);
}
