#include <bits/stdc++.h>
using namespace std;
long long const K = 5001;
long long n, k;
vector<pair<long, long> > v;
vector<long long> b;
long long const N = 1e5 + 10;
long long a[N];
bool comp(pair<long, long> i, pair<long, long> j) {
  return abs(a[i.first] - a[i.second]) < abs(a[j.first] - a[j.second]);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> k >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (long long i = 0; i < n - 1; i++) {
    v.push_back({i, i + 1});
    b.push_back(a[i]);
  }
  b.push_back(a[n - 1]);
  sort(b.begin(), b.end());
  n = b.size();
  long long dp[3][k + 3];
  for (long long i = 0; i <= 2; i++) {
    for (long long j = 1; j <= k + 2; j++) {
      dp[i][j] = 1e14;
    }
  }
  dp[1][0] = 0;
  dp[0][0] = 0;
  dp[1][1] = b[1] - b[0];
  for (long long i = 2; i < n; i++) {
    for (long long j = k; j >= 1; j--) {
      dp[i % 3][j] =
          min(dp[(i + 2) % 3][j], dp[(i + 1) % 3][j - 1] + b[i] - b[i - 1]);
    }
  }
  long long ans = min(dp[0][k], dp[1][k]);
  ans = min(ans, dp[2][k]);
  cout << ans << endl;
  return 0;
}
