#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e18;
vector<int> a;
int k, n;
pair<long long, long long> check(long long md) {
  vector<pair<long long, long long>> dp(n + 1, {oo, oo});
  dp[0] = dp[1] = {0, 0};
  for (int i = 2; i <= n; i++) {
    dp[i] = dp[i - 1];
    pair<long long, long long> nxt = dp[i - 2];
    nxt.first -= md;
    nxt.first += a[i] - a[i - 1];
    nxt.second++;
    dp[i] = min(dp[i], nxt);
  }
  return dp[n];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  cin >> k >> n;
  a = vector<int>(n + 1, 0);
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  long long md, lo = 0, hi = 1e10, lamda = -1;
  while (lo <= hi) {
    md = (lo + hi) / 2;
    long long used = check(md).second;
    if (used > k) {
      hi = md - 1;
    } else {
      lamda = md;
      lo = md + 1;
    }
  }
  pair<long long, long long> ans = check(lamda);
  long long val = ans.first + k * lamda;
  cout << val << endl;
}
