#include <bits/stdc++.h>
using namespace std;
namespace SHENZHEBEI {
static const long long GYN = 2333333;
char SZB[GYN], *S = SZB, *T = SZB;
inline char gc() {
  if (S == T) {
    T = (S = SZB) + fread(SZB, 1, GYN, stdin);
    if (S == T) return '\n';
  }
  return *S++;
}
inline long long read() {
  long long x = 0;
  char ch = gc();
  for (; !isdigit(ch); ch = gc())
    ;
  for (; isdigit(ch); ch = gc()) x = x * 10 - 48 + ch;
  return x;
}
inline void write(long long x) {
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline char readchar() {
  char ch = gc();
  for (; isspace(ch); ch = gc())
    ;
  return ch;
}
inline long long readstr(char *s) {
  char ch = gc();
  long long cur = 0;
  for (; isspace(ch); ch = gc())
    ;
  for (; !isspace(ch); ch = gc()) s[cur++] = ch;
  s[cur] = '\0';
  return cur;
}
void writeln(long long x) {
  write(x);
  puts("");
}
}  // namespace SHENZHEBEI
using namespace SHENZHEBEI;
using namespace std;
long long n, ans, k, a[1000000], kk;
bool flag[1000000];
struct lsg {
  long long x, l, r, d;
} f[1000000];
void delit() {
  f[1] = f[k];
  k--;
  long long kk = 0, x = 1;
  for (; kk < x;) {
    kk = x;
    if (kk * 2 <= k && f[kk * 2].x < f[x].x) x = kk * 2;
    if (kk * 2 + 1 <= k && f[kk * 2 + 1].x < f[x].x) x = kk * 2 + 1;
    swap(f[kk], f[x]);
  }
}
bool pd(lsg x, lsg y) { return x.x < y.x; }
signed main() {
  kk = read();
  n = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  sort(a + 1, a + 1 + n);
  k = n + 1;
  for (long long i = 1; i <= n - 1; i++)
    f[i].x = a[i] = a[i + 1] - a[i], f[i].l = i - 1, f[i].r = i + 1, f[i].d = i;
  f[n].x = 1e15;
  f[n + 1].x = 1e15;
  f[n].d = 0;
  f[n + 1].d = n;
  a[0] = a[n] = 1e15;
  sort(f + 1, f + 1 + k, pd);
  while (kk--) {
    while (flag[f[1].d]) delit();
    while (flag[f[1].l]) f[1].l--;
    while (flag[f[1].r]) f[1].r++;
    ans += f[1].x;
    f[1].x = a[f[1].d] = a[f[1].l] + a[f[1].r] - f[1].x;
    flag[f[1].l] = true;
    flag[f[1].r] = true;
    f[1].l--;
    f[1].r++;
    f[++k] = f[1];
    delit();
  }
  writeln(ans);
}
