#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int k, n, x[N], a[N], pre[N], nxt[N], ans;
bool vis[N];
struct data {
  int x, num;
  bool operator<(const data &s) const { return s.x < x; }
};
priority_queue<data> small;
inline char tc(void) {
  static char fl[100000], *A = fl, *B = fl;
  return A == B && (B = (A = fl) + fread(fl, 1, 100000, stdin), A == B) ? EOF
                                                                        : *A++;
}
inline void read(int &x) {
  x = 0;
  char ch = tc();
  while (ch < '0' || ch > '9') ch = tc();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = tc();
}
int main() {
  register int i;
  read(k);
  read(n);
  for (i = 1; i <= n; ++i) read(x[i]);
  sort(x + 1, x + n + 1);
  for (i = 2; i <= n; ++i) {
    a[i - 1] = x[i] - x[i - 1];
    pre[i - 1] = i - 2;
    nxt[i - 1] = i;
    small.push((data){a[i - 1], i - 1});
  }
  a[0] = a[n] = 1e9;
  pre[n] = n - 1;
  nxt[0] = 1;
  while (k--) {
    while (vis[small.top().num]) small.pop();
    data p = small.top();
    small.pop();
    ans += p.x;
    p.x = a[pre[p.num]] + a[nxt[p.num]] - a[p.num];
    vis[pre[p.num]] = vis[nxt[p.num]] = 1;
    pre[p.num] = pre[pre[p.num]];
    pre[nxt[p.num]] = p.num;
    nxt[p.num] = nxt[nxt[p.num]];
    nxt[pre[p.num]] = p.num;
    small.push(p);
  }
  printf("%d", ans);
  return 0;
}
