#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
pair<int, int> p[maxn], q[maxn];
int t[maxn];
int tot;
int n, k;
int dp[maxn][2];
void solve() {
  memset(dp, 0x3f3f3f3f, sizeof(dp));
  int e = 0;
  for (int i = 1; i <= tot; i++) {
    dp[i][e] = min(dp[i - 1][e], q[i].second - q[i].first);
  }
  e ^= 1;
  for (int ki = 2; ki <= k; ki++, e ^= 1) {
    dp[1][e] = 0x3f3f3f3f;
    for (int i = 2; i <= tot; i++) {
      bool last = q[i - 1].second == q[i].first;
      dp[i][e] =
          min(dp[i - 1 - last][e ^ 1] + q[i].second - q[i].first, dp[i - 1][e]);
    }
  }
  cout << dp[tot][e ^ 1] << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> k >> n;
  for (int i = 0; i < n; i++) cin >> t[i];
  sort(t, t + n);
  for (int i = 1; i < n; i++) {
    p[i] = make_pair(t[i - 1], t[i]);
  }
  sort(p + 1, p + n, [](const pair<int, int> &x, const pair<int, int> &y) {
    return (x.second - x.first) < (y.second - y.first);
  });
  tot = min(3 * k, n - 1);
  for (int i = 1; i <= tot; i++) {
    q[i] = p[i];
  }
  sort(q + 1, q + tot + 1,
       [](const pair<int, int> &x, const pair<int, int> &y) {
         return x.first < y.first;
       });
  solve();
  return 0;
}
