#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T readin(T x) {
  x = 0;
  int f = 0;
  char c;
  while ((c = getchar()) < '0' || '9' < c)
    if (c == '-') f = 1;
  for (x = (c ^ 48); '0' <= (c = getchar()) && c <= '9';
       x = (x << 1) + (x << 3) + (c ^ 48))
    ;
  return f ? -x : x;
}
const int maxn = 500000;
int n, k;
int a[maxn + 5], t[maxn + 5];
inline void input() {
  k = readin(1), n = readin(1);
  for (int i = 1; i <= n; ++i) a[i] = readin(1);
  sort(a + 1, a + n + 1);
  --n;
  for (int i = 1; i <= n; ++i) t[i] = a[i + 1] - a[i];
}
struct node {
  long long val;
  int cnt;
  node() {}
  node(const long long V, const int C) : val(V), cnt(C) {}
  inline node operator+(const node rhs) const {
    return node(val + rhs.val, cnt + rhs.cnt);
  }
  inline int operator<(const node rhs) const {
    if (val == rhs.val) return cnt < rhs.cnt;
    return val < rhs.val;
  }
} f[maxn + 5][2];
inline void getf(const long long x) {
  f[1][0] = node(0, 0);
  f[1][1] = node(t[1] - x, 1);
  for (int i = 2; i <= n; ++i) {
    f[i][0] = min(f[i - 1][0], f[i - 1][1]);
    f[i][1] = f[i - 1][0] + node(t[i] - x, 1);
  }
}
long long pre[maxn + 5];
inline void bisearch() {
  long long l = 0, r = 0, mid, ans;
  for (int i = 1; i <= n; ++i) r += t[i];
  while (l <= r) {
    mid = (l + r) >> 1;
    getf(mid);
    f[n][0] = min(f[n][0], f[n][1]);
    if (f[n][0].cnt <= k)
      ans = f[n][0].val + k * mid, l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%lld\n", ans);
}
signed main() {
  input();
  bisearch();
  return 0;
}
