#include <bits/stdc++.h>
using namespace std;
const int mod1 = 1e9 + 7, mod2 = 998244353, maxn = 5e5 + 5, maxk = 5005, K = 26;
const long long infll = 1e18;
const double pi = acos(-1);
int k, n;
int times[maxn];
vector<pair<int, int> > d;
pair<int, int> diff[maxn];
int dp[2][maxk][2];
void solve() {
  cin >> k >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> times[i];
  }
  sort(times + 1, times + n + 1);
  for (int i = 1; i < n; ++i) {
    diff[i].first = times[i + 1] - times[i];
    diff[i].second = i;
  }
  sort(diff + 1, diff + n);
  for (int i = 1; i <= min(n - 1, 3 * k); ++i) {
    d.push_back(make_pair(diff[i].second, diff[i].first));
  }
  d.push_back(make_pair(0, 0));
  sort(d.begin(), d.end());
  for (int i = 0; i <= 1; ++i) {
    for (int j = 0; j <= k; ++j) {
      for (int c = 0; c <= 1; ++c) {
        dp[i][j][c] = 1e9 + 124;
      }
    }
  }
  dp[0][0][0] = 0;
  int N = d.size();
  for (int i = 1; i <= N - 1; ++i) {
    for (int j = 0; j <= min(i, k); ++j) {
      dp[i % 2][j][0] = min(dp[(i - 1) % 2][j][0], dp[(i - 1) % 2][j][1]);
      if (j > 0) dp[i % 2][j][1] = dp[(i - 1) % 2][j - 1][0] + d[i].second;
    }
  }
  cout << min(dp[(N - 1) % 2][k][0], dp[(N - 1) % 2][k][1]);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
