#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T sqr(T x) {
  return x * x;
}
template <typename T>
inline T gcd(T a, T b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
template <typename T>
inline T lcm(T a, T b) {
  return (a / gcd(a, b)) * b;
}
template <class T>
inline double dist(pair<T, T> a, pair<T, T> b) {
  return sqrt(sqr(a.first - b.first) + sqr(a.second - b.second));
}
template <class T>
inline T dist_square(pair<T, T> a, pair<T, T> b) {
  return (sqr(a.first - b.first) + sqr(a.second - b.second));
}
template <class T>
inline T cross(pair<T, T> a, pair<T, T> b, pair<T, T> c = {0, 0}) {
  return (a.first - c.first) * (b.second - c.second) -
         (a.second - c.second) * (b.first - c.first);
}
template <class T>
inline T dot(pair<T, T> a, pair<T, T> b, pair<T, T> c = {0, 0}) {
  return (a.first - c.first) * (b.first - c.first) +
         (a.second - c.second) * (b.second - c.second);
}
template <class T>
inline int sign(T a) {
  return (a < 0 ? -1 : a ? 1 : 0);
}
template <class T>
inline int popcnt(T x) {
  int cnt = 0;
  while (x) x = (x & (x - 1)), cnt++;
  return cnt;
}
bool is_prime(long long n) {
  if (n < 2) return 0;
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) return 0;
  return 1;
}
long long powi(long long a, long long b, long long mod) {
  long long c = 1;
  while (b) {
    if (b & 1) c = (c * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return c;
}
const double PI = 3.1415926535897932384626433;
const long long LLINF = 9000000000000043LL;
const int INF = 1000000043;
const long long mod7 = 1000000007;
const long long mod9 = 1000000009;
int main() {
  ios::sync_with_stdio(0);
  int n, k;
  cin >> k >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); i++) cin >> a[i];
  sort((a).begin(), (a).end());
  n--;
  vector<pair<int, int>> c(n);
  for (int i = 0; i < (n); i++) {
    c[i].first = a[i + 1] - a[i];
    c[i].second = i;
  }
  sort((c).begin(), (c).end());
  while (c.size() > 4 * k) {
    c.pop_back();
  }
  sort((c).begin(), (c).end(),
       [](pair<int, int> a, pair<int, int> b) { return a.second < b.second; });
  vector<vector<vector<long long>>> dp(
      2, vector<vector<long long>>(2, vector<long long>(k + 1, LLINF)));
  long long ans = LLINF;
  dp[1][0][0] = 0;
  for (int i = 0; i < (c.size()); i++) {
    int bit = (i & 1);
    dp[bit] = vector<vector<long long>>(2, vector<long long>(k + 1, LLINF));
    for (int j = 0; j <= k; j++) {
      dp[bit][0][j] = min(dp[bit ^ 1][0][j], dp[bit ^ 1][1][j]);
      if (j) {
        if (i && c[i - 1].second + 1 == c[i].second) {
          dp[bit][1][j] = dp[bit ^ 1][0][j - 1] + c[i].first;
        } else {
          dp[bit][1][j] =
              min(dp[bit ^ 1][0][j - 1], dp[bit ^ 1][1][j - 1]) + c[i].first;
        }
      }
    }
    ans = min(ans, dp[bit][1][k]);
  }
  cout << ans << endl;
}
