#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
constexpr auto MOD = 1000000007LL;
constexpr auto LINF = (1LL << 60);
constexpr auto INF = 2147483647LL;
constexpr auto PI = 3.1415926535897932384626433;
constexpr auto EPS = 1E-9;
template <typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2> p) {
  out << p.first << ' ' << p.second;
  return out;
}
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
  in >> p.first >> p.second;
  return in;
}
template <typename T>
istream& operator>>(istream& in, vector<T> v) {
  for (auto& x : v) cin >> x;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> v) {
  for (int i = 0; i < v.size(); i++)
    cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
constexpr auto MAXN = 500010;
int n, k, a[MAXN], ord[MAXN], dp[4][5010];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> k >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 0; i + 1 < n; i++) cerr << a[i + 1] - a[i] << endl;
  iota(ord, ord + n, 0);
  sort(ord, ord + n - 1, [](int x, int y) {
    int i = a[x + 1] - a[x];
    int j = a[y + 1] - a[y];
    if (i != j) return i < j;
    return x < y;
  });
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 5010; j++) dp[i][j] = MOD;
  dp[0][0] = 0;
  n = min(k * 4, n - 1);
  sort(ord, ord + n);
  int res = MOD;
  for (int i = 0; i < n; i++) {
    int i0 = i % 4;
    for (int j = 0; j <= k; j++) {
      dp[(i0 + 1) % 4][j] = min(dp[(i0 + 1) % 4][j], dp[i0][j]);
      dp[(i0 + 1 + (ord[i] + 1 == ord[i + 1])) % 4][j + 1] =
          min(dp[(i0 + 1 + (ord[i] + 1 == ord[i + 1])) % 4][j + 1],
              dp[i0][j] + a[ord[i] + 1] - a[ord[i]]);
    }
  }
  for (int i = 0; i < 4; i++) res = min(res, dp[i][k]);
  cout << res << endl;
  return 0;
}
