#include <bits/stdc++.h>
using namespace std;
int a[500005];
int l[500005], r[500005];
int heap[500005];
int local[500005];
int pointer[500005];
int num = 1;
void rotate(int x) {
  if (heap[x] < heap[x / 2]) {
    swap(heap[x], heap[x / 2]);
    swap(pointer[local[x]], pointer[local[x / 2]]);
    swap(local[x], local[x / 2]);
    rotate(x / 2);
  }
}
void down_rotate(int x) {
  if (x * 2 >= num) return;
  int t;
  if (heap[x * 2] < heap[x * 2 + 1])
    t = x * 2;
  else
    t = x * 2 + 1;
  if (x * 2 + 1 >= num) t = x * 2;
  if (heap[t] < heap[x]) {
    swap(heap[t], heap[x]);
    swap(pointer[local[t]], pointer[local[x]]);
    swap(local[t], local[x]);
    down_rotate(t);
  }
}
int main() {
  int n, k;
  scanf("%d%d", &k, &n);
  int i;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a, a + n);
  for (i = 0; i < n - 1; i++) {
    a[i] = a[i + 1] - a[i];
  }
  n--;
  for (i = 0; i < n; i++) {
    l[i] = i - 1;
    r[i] = i + 1;
    local[num] = i;
    heap[num] = a[i];
    pointer[i] = num;
    num++;
    rotate(pointer[i]);
  }
  int sum = 0;
  for (i = 0; i < k; i++) {
    sum += heap[1];
    num--;
    int now = local[1];
    swap(heap[1], heap[num]);
    swap(pointer[local[1]], pointer[local[num]]);
    swap(local[1], local[num]);
    down_rotate(1);
    int tl = l[now];
    int tr = r[now];
    int temp;
    if (tl >= 0) {
      l[now] = l[tl];
      num--;
      temp = pointer[tl];
      swap(heap[temp], heap[num]);
      swap(pointer[local[temp]], pointer[local[num]]);
      swap(local[temp], local[num]);
      down_rotate(temp);
      rotate(temp);
      if (l[tl] >= 0) r[l[tl]] = n;
    }
    if (tr < n) {
      r[now] = r[tr];
      num--;
      temp = pointer[tr];
      swap(heap[temp], heap[num]);
      swap(pointer[local[temp]], pointer[local[num]]);
      swap(local[temp], local[num]);
      down_rotate(temp);
      rotate(temp);
      if (r[tr] < n) l[r[tr]] = -1;
    }
    if ((tl >= 0) && (tr < n)) {
      if (l[tl] >= 0) r[l[tl]] = now;
      if (r[tr] < n) l[r[tr]] = now;
      a[now] = a[tl] + a[tr] - a[now];
      heap[num] = a[now];
      local[num] = now;
      pointer[now] = num;
      num++;
      rotate(pointer[now]);
    }
  }
  printf("%d\n", sum);
  return 0;
}
