#include <bits/stdc++.h>
using namespace std;
int n, k;
long long dp[4][5001];
int ar[500001], u[500001];
vector<int> vec;
pair<int, pair<int, int> > ars[500001];
int main() {
  cin >> k >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ar[i]);
  }
  sort(ar + 1, ar + n + 1);
  for (int i = 2; i <= n; i++)
    ars[i] = make_pair(ar[i] - ar[i - 1], make_pair(i - 1, i));
  sort(ars + 2, ars + n + 1);
  for (int i = 2; i <= k * 2 + 1; i++) {
    u[ars[i].second.first] = 1;
    u[ars[i].second.second] = 1;
  }
  vec.push_back(0);
  for (int i = 1; i <= n; i++)
    if (u[i] == 1) vec.push_back(ar[i]);
  for (int i = 0; i < 4; i++)
    for (int j = 1; j < 5001; j++) dp[i][j] = 1e18;
  for (int i = 2; i < vec.size(); i++) {
    for (int j = 1; j <= k; j++) {
      dp[3][j] = dp[3 - 1][j];
      dp[3][j] = min(dp[3][j], dp[3 - 2][j - 1] + (vec[i] - vec[i - 1]));
    }
    for (int a = 0; a < 3; a++)
      for (int b = 1; b < 5001; b++) dp[a][b] = dp[a + 1][b];
  }
  cout << dp[3][k];
  return 0;
}
