#include <bits/stdc++.h>
using namespace std;
struct node {
  int num, pos, l, r;
  node(int _num = 0, int _pos = 0, int _l = 0, int _r = 0) {
    num = _num;
    pos = _pos;
    l = _l;
    r = _r;
  }
  bool operator<(const node& x) const { return num > x.num; }
} t[500001];
bool used[500001];
int k, n, a[500001];
priority_queue<node> q;
int main() {
  int ans = 0;
  scanf("%d%d", &k, &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  std::sort(a + 1, a + n + 1);
  for (int i = 1; i < n; ++i)
    q.push(t[i] = node(a[i] = a[i + 1] - a[i], i, i - 1, i + 1));
  t[0].num = t[n].num = 1000000050;
  t[n].pos = n;
  while (k) {
    node temp = q.top();
    q.pop();
    if (used[temp.pos]) continue;
    --k;
    ans += temp.num;
    used[temp.l] = used[temp.r] = 1;
    temp.num = t[temp.l].num + t[temp.r].num - temp.num;
    temp.l = t[temp.l].l;
    temp.r = t[temp.r].r;
    t[temp.l].r = t[temp.r].l = temp.pos;
    q.push(t[temp.pos] = temp);
  }
  printf("%d\n", ans);
  return 0;
}
