#include <bits/stdc++.h>
using namespace std;
const long long N = 5e3 + 2;
long long k, n, a[500005], dp[5][N];
vector<pair<long long, long long> > vc;
pair<long long, long long> b[500005];
void Input() {
  cin >> k >> n;
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  sort(a + 1, a + 1 + n);
  for (long long i = 2; i <= n; ++i) {
    b[i - 1].first = a[i] - a[i - 1];
    b[i - 1].second = i;
  }
}
void Collect() {
  sort(b + 1, b + n);
  vc.push_back({-2, -1});
  for (long long i = 1; i <= min(4 * k + 1, n - 1); ++i) {
    vc.push_back({b[i].second, b[i].first});
  }
  sort((vc).begin(), (vc).end());
}
void Solve() {
  Collect();
  memset(dp, 0x3f, sizeof dp);
  dp[1][0] = 0;
  long long End = vc.size() - 1;
  long long x = 1, y = 0, z = 2;
  for (long long i = 1; i <= End; ++i) {
    x = (x + 1) % 3;
    y = (y + 1) % 3;
    z = (z + 1) % 3;
    for (long long Use = 0; Use <= k; ++Use) {
      dp[x][Use] = dp[y][Use];
      if (Use == 0) continue;
      dp[x][Use] = min(dp[x][Use], dp[z][Use - 1] + vc[i].second);
      if (vc[i].first - vc[i - 1].first > 1)
        dp[x][Use] = min(dp[x][Use], dp[y][Use - 1] + vc[i].second);
    }
  }
  cout << dp[x][k];
}
int main() {
  if (fopen("trash.inp", "r"))
    freopen("trash.inp", "r", stdin), freopen("trash.out", "w", stdout);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  Input();
  Solve();
}
