#include <bits/stdc++.h>
#pragma GCC optimization("O3")
using namespace std;
template <typename T>
inline void Cin(T& first) {
  char c;
  T sign = 1;
  first = 0;
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    if (c == '-') sign = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) first = first * 10 + c - '0';
  first *= sign;
}
template <typename T>
inline void Out(T first) {
  if (first > 9) Out(first / 10);
  putchar(first % 10 + '0');
}
template <typename T>
inline void Cout(T first, char c) {
  if (first < 0) putchar('-');
  first = abs(first);
  Out(first);
  putchar(c);
}
template <typename T, typename... Args>
inline void Cin(T& a, Args&... args) {
  Cin(a);
  Cin(args...);
}
template <typename T, typename... Args>
inline void Cout(T a, char c, Args... args) {
  Cout(a, c);
  Cout(args...);
}
const int N = 5002;
const int M = int(5e5) + 2;
const long long oo = (long long)1e10;
int n, k, _a[M], cur[3];
vector<long long> f[3];
struct TIrene {
  int first, i;
  bool operator<(const TIrene& o) const& { return i < o.i; }
} a[M];
void Enter() {
  cin >> k >> n;
  for (int i = 0; i < n; ++i) cin >> _a[i];
  sort(_a, _a + n);
  for (int i = 0; i < n; ++i) {
    if (i) a[i].first = _a[i] - _a[i - 1];
    a[i].i = i;
  }
  sort(a + 1, a + n, [](const TIrene& a, const TIrene& b) {
    if (a.first != b.first) return a.first < b.first;
    return a.i > b.i;
  });
  int _n = 2 * k, cnt = k;
  while (_n <= n && a[_n].first == a[_n - 1].first && cnt) ++_n, --cnt;
  n = _n;
  sort(a + 1, a + n);
}
void Solve() {
  for (int i = 0; i < 3; ++i) {
    f[i].resize(k + 1);
    fill(f[i].begin(), f[i].end(), oo);
    cur[i] = i;
  }
  for (int i = 1; i < n; ++i) {
    if (i - 1)
      f[cur[2]][1] = min(f[cur[1]][1], (long long)a[i].first);
    else
      f[cur[2]][1] = a[1].first;
    for (int j = 2, l = min(k, i); j <= l; ++j) {
      if (a[i].i > a[i - 1].i + 1)
        f[cur[2]][j] = min(f[cur[1]][j], f[cur[1]][j - 1] + a[i].first);
      else
        f[cur[2]][j] = min(f[cur[1]][j], f[cur[0]][j - 1] + a[i].first);
    }
    int t = cur[0];
    cur[0] = cur[1], cur[1] = cur[2], cur[2] = t;
  }
  cout << f[cur[1]][k];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (fopen("test"
            ".inp",
            "r")) {
    freopen(
        "test"
        ".inp",
        "r", stdin);
    freopen(
        "test"
        ".out",
        "w", stdout);
  }
  Enter(), Solve();
  return 0;
}
