#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;
int n, k, _a[M];
int f[2 * N][N];
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) { return a.first < b.first; });
  n = 2 * k;
  sort(a + 1, a + n);
}
void Solve() {
  int res = (int)1111111111;
  fill_n(&f[0][0], 2 * N * N, 1111111111);
  for (int i = 1; i < n; ++i) {
    if (i - 1)
      f[i][1] = min(f[i - 1][1], a[i].first);
    else
      f[i][1] = a[1].first;
    for (int j = 2, l = min(k, i); j <= l; ++j) {
      f[i][j] = min(f[i - 1][j], f[i - 2][j - 1] + a[i].first);
      if (a[i].i > a[i - 1].i + 1)
        f[i][j] = min(f[i][j], f[i - 1][j - 1] + a[i].first);
    }
  }
  cout << f[n - 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;
}
