#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5 + 3;
const long long K = 5004;
const long long inf = 1e9 + 2;
long long a[N], dif[N], n, k;
long long dp[4][K];
vector<pair<long long, long long> > v, v1;
signed main() {
  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++) {
    dif[i] = a[i] - a[i - 1];
  }
  if (n <= 3 * k + 1) {
    for (long long i = 0; i < 3; i++) {
      for (long long j = 1; j <= k; j++) {
        dp[i][j] = inf;
      }
    }
    for (long long i = 2; i <= n; i++) {
      for (long long j = 1; j <= min(i, k); j++) {
        dp[i % 3][j] = min(dp[(i + 1) % 3][j - 1] + dif[i], dp[(i + 2) % 3][j]);
      }
    }
    cout << dp[n % 3][k] << '\n';
  } else {
    for (long long i = 2; i <= n; i++) {
      v.push_back({dif[i], i});
    }
    sort(v.begin(), v.end());
    for (long long i = 0; i < 3 * k; i++) {
      v1.push_back({v[i].second, v[i].first});
    }
    v1.push_back({0, 0});
    sort(v1.begin(), v1.end());
    for (long long i = 0; i < 3; i++) {
      for (long long j = 1; j <= k; j++) {
        dp[i][j] = inf;
      }
    }
    dp[0][0] = 0;
    for (long long i = 1; i <= 3 * k; i++) {
      for (long long j = 1; j <= min(i, k); j++) {
        if (v1[i].first - v1[i - 1].first > 1)
          dp[i % 3][j] =
              min(dp[(i + 2) % 3][j - 1] + v1[i].second, dp[(i + 2) % 3][j]);
        else
          dp[i % 3][j] =
              min(dp[(i + 1) % 3][j - 1] + v1[i].second, dp[(i + 2) % 3][j]);
      }
    }
    cout << dp[0][k];
  }
}
