#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int N = 500005;
const int K = 5005;
int k, n, x, ship[N];
pair<int, int> secondShip[N];
long long int dp[2][K][2];
bool compare(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
int process() {
  dp[0][0][0] = 0;
  dp[0][1][1] = 1ll * secondShip[0].first;
  for (int a = 1; a < min(3 * k, n - 1); a += 1) {
    dp[1][0][0] = 0;
    dp[1][0][1] = (int)(1e18 + 7);
    for (int b = 1; b < min(a, k) + 1; b += 1) {
      dp[1][b][0] = min(dp[0][b][0], dp[0][b][1]);
      dp[1][b][1] = dp[0][b - 1][0];
      if ((secondShip[a].second - 1) != secondShip[a - 1].second) {
        dp[1][b][1] = min(dp[1][b][1], dp[0][b - 1][1]);
      }
      dp[1][b][1] = dp[1][b][1] + secondShip[a].first;
    }
    for (int j = 0; j < a + 1; j += 1) {
      dp[0][j][0] = dp[1][j][0];
      dp[0][j][1] = dp[1][j][1];
    }
  }
  return min(dp[0][k][0], dp[0][k][1]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> k >> n;
  for (int i = 0; i < n; i += 1) {
    cin >> ship[i];
  }
  sort(ship, ship + n);
  for (int i = 0; i < n - 1; i += 1) {
    secondShip[i] = make_pair(ship[i + 1] - ship[i], i);
  }
  sort(secondShip, secondShip + n - 1);
  sort(secondShip, secondShip + min(3 * k, n - 1), compare);
  for (int i = 0; i < 2; i += 1) {
    for (int j = 1; j < k + 1; j += 1) {
      dp[i][j][0] = dp[i][j][1] = (int)(1e18 + 7);
    }
  }
  cout << process();
  return 0;
}
