#include <bits/stdc++.h>
using namespace std;
int num[1000005], n;
int ans;
int heap[1000005], fheap[1000005], a[1000005], sz;
int pre[1000005], nxt[1000005], k;
int x1, x2;
inline void swap(int &x, int &y) { x ^= y, y ^= x, x ^= y; }
inline void del(int x) {
  heap[x] = heap[sz--];
  fheap[heap[x]] = x;
  int now = x, nxt;
  if (num[heap[now]] >= num[heap[now >> 1]]) {
    nxt = now << 1;
    while (nxt <= sz) {
      if (nxt < sz) nxt = num[heap[nxt]] < num[heap[nxt | 1]] ? nxt : nxt | 1;
      if (num[heap[now]] <= num[heap[nxt]]) break;
      swap(heap[now], heap[nxt]);
      fheap[heap[now]] = now;
      fheap[heap[nxt]] = nxt;
      now = nxt;
      nxt = now << 1;
    }
  } else {
    nxt = now >> 1;
    while (nxt) {
      if (num[heap[now]] >= num[heap[nxt]]) break;
      swap(heap[now], heap[nxt]);
      fheap[heap[now]] = now;
      fheap[heap[nxt]] = nxt;
      now = nxt, nxt = now >> 1;
    }
  }
}
inline void push(int x) {
  heap[++sz] = x;
  fheap[x] = sz;
  int now = sz, nxt = now >> 1;
  while (nxt) {
    if (num[heap[now]] >= num[heap[nxt]]) break;
    swap(heap[now], heap[nxt]);
    fheap[heap[now]] = now;
    fheap[heap[nxt]] = nxt;
    now = nxt, nxt = now >> 1;
  }
}
inline void read(int &ans, char ch = getchar()) {
  ans = 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9'; ans = ans * 10 + ch - 48, ch = getchar())
    ;
}
int main() {
  read(k), read(n);
  for (int i = 1; i <= n; i++) read(a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 2; i <= n; i++) {
    pre[i] = i - 1;
    nxt[i] = i + 1;
    num[i] = a[i] - a[i - 1];
    push(i);
  }
  num[1] = 1e9 + 7;
  num[n + 1] = 1e9 + 7;
  push(1);
  push(++n);
  for (int i = 1; i <= k; i++) {
    int x = heap[1];
    del(1);
    del(fheap[pre[x]]);
    del(fheap[nxt[x]]);
    x1 = num[pre[x]], x2 = num[nxt[x]];
    num[++n] = x1 + x2 - num[x];
    ans += num[x];
    pre[n] = pre[pre[x]];
    nxt[n] = nxt[nxt[x]];
    nxt[pre[pre[x]]] = n;
    pre[nxt[nxt[x]]] = n;
    push(n);
  }
  printf("%d", ans);
}
