#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[3][K][2];
bool compare(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
int process() {
  dp[1][0][0] = 0;
  dp[1][1][1] = 1ll * secondShip[0].first;
  for (int a = 1; a < min(3 * k, n); a += 1) {
    dp[2][1][0] = min(dp[1][1][0], dp[1][1][1]);
    dp[2][1][1] = 1ll * secondShip[a].first;
    for (int b = 2; b < a + 1; b += 1) {
      dp[2][b][0] =
          min(min(dp[1][b][0], dp[1][b][1]), min(dp[0][b][0], dp[0][b][1]));
      dp[2][b][1] = min(min(dp[0][b - 1][0], dp[0][b - 1][1]), dp[1][b - 1][0]);
      if ((secondShip[a].second - 1) != secondShip[a - 1].second) {
        dp[2][b][1] = min(dp[2][b][1], dp[1][b - 1][1]);
      }
      dp[2][b][1] = dp[2][b][1] + secondShip[a].first;
    }
    for (int i = 0; i < 2; i += 1) {
      for (int j = 0; j < a + 1; j += 1) {
        dp[i][j][0] = dp[i + 1][j][0];
        dp[i][j][1] = dp[i + 1][j][1];
      }
    }
  }
  return min(dp[1][k][0], dp[1][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);
  n--;
  for (int i = 0; i < n; i += 1) {
    secondShip[i].first = ship[i + 1] - ship[i];
    secondShip[i].second = i + 1;
  }
  sort(secondShip, secondShip + n);
  sort(secondShip, secondShip + min(3 * k, n), compare);
  for (int i = 0; i < 3; i += 1) {
    for (int j = 0; j < k + 1; j += 1) {
      dp[i][j][0] = dp[i][j][1] = (int)(1e9 + 7);
    }
  }
  cout << process();
  return 0;
}
