#include <bits/stdc++.h>
using namespace std;
struct node {
  int value, place;
  friend bool operator<(node x, node y) { return x.value > y.value; }
};
priority_queue<node> q;
int n, m, Ans, chose, nxt[(500000 + 50)], pre[(500000 + 50)], w[(500000 + 50)],
    l, r, a[(500000 + 50)];
bool vis[(500000 + 50)];
void change(int x) {
  vis[x] = 1;
  nxt[pre[x]] = nxt[x];
  pre[nxt[x]] = pre[x];
  nxt[x] = 0;
  pre[x] = 0;
}
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  n--;
  for (int i = 1; i <= n; i++) w[i] = a[i + 1] - a[i];
  for (int i = 0; i <= n; i++) nxt[i] = i + 1;
  nxt[n] = n;
  for (int i = 2; i <= n + 1; i++) pre[i] = i - 1;
  pre[1] = 1;
  for (int i = 1; i <= n; i++) q.push((node){w[i], i});
  for (int i = 1; i <= m; i++) {
    while (vis[q.top().place]) q.pop();
    node temp = q.top();
    q.pop();
    Ans += temp.value;
    l = pre[temp.place];
    r = nxt[temp.place];
    w[temp.place] = w[l] + w[r] - w[temp.place];
    change(l);
    change(r);
    q.push((node){w[temp.place], temp.place});
  }
  printf("%d\n", Ans);
  return 0;
}
