#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500005;
const long long INF = (1ll << 60);
int n, k;
bool vis[MAXN];
long long ans, s[MAXN], a[MAXN];
long long Read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x * 10) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
template <typename T>
void Put1(T x) {
  if (x > 9) Put1(x / 10);
  putchar(x % 10 ^ 48);
}
template <typename T>
void Put(T x, char c = -1) {
  if (x < 0) putchar('-'), x = -x;
  Put1(x);
  if (c >= 0) putchar(c);
}
template <typename T>
T Max(T x, T y) {
  return x > y ? x : y;
}
template <typename T>
T Min(T x, T y) {
  return x < y ? x : y;
}
template <typename T>
T Abs(T x) {
  return x < 0 ? -x : x;
}
int pre[MAXN], suf[MAXN];
struct node {
  long long ID, val;
  node() {}
  node(long long ID1, long long val1) {
    ID = ID1;
    val = val1;
  }
  bool operator<(const node &px) const { return val > px.val; }
};
priority_queue<node> q;
int main() {
  k = Read();
  n = Read();
  for (int i = 0; i < n; ++i) a[i] = Read();
  sort(a, a + n);
  for (int i = 1; i < n; ++i)
    q.push(node(i, s[i] = a[i] - a[i - 1])), pre[i] = i - 1, suf[i] = i + 1;
  s[0] = s[n] = INF;
  for (int i = 1; i <= k; ++i) {
    while (vis[q.top().ID]) q.pop();
    node t = q.top();
    q.pop();
    ans += t.val;
    vis[pre[t.ID]] = vis[suf[t.ID]] = 1;
    q.push(node(t.ID, s[t.ID] = -t.val + s[pre[t.ID]] + s[suf[t.ID]]));
    pre[t.ID] = pre[pre[t.ID]];
    suf[pre[t.ID]] = t.ID;
    suf[t.ID] = suf[suf[t.ID]];
    pre[suf[t.ID]] = t.ID;
  }
  Put(ans);
  return 0;
}
