#include <bits/stdc++.h>
using namespace std;
int k, n;
int t[500010];
pair<int, int> intervals[500010];
int dist[500010];
bool v[500010];
int dp[4][5010];
int main() {
  cin >> k >> n;
  for (int i = 1; i <= n; i++) cin >> t[i];
  sort(t + 1, t + n + 1);
  for (int i = 1; i < n; i++) {
    dist[i] = intervals[i].first = t[i + 1] - t[i];
    intervals[i].second = i;
  }
  sort(intervals + 1, intervals + n);
  for (int i = 1; i <= min(n, 3 * k); i++) v[intervals[i].second] = true;
  memset(dp, 0x3f, sizeof dp);
  dp[0][0] = 0;
  dp[1][0] = 0;
  dp[2][0] = 0;
  dp[3][0] = 0;
  int p = 0;
  for (int i = 1; i < n; i++) {
    if (!v[i]) continue;
    p++;
    for (int j = 1; j <= min(p, k); j++)
      dp[p & 3][j] =
          min(dp[(p - 1) & 3][j], dp[(p - 1 - v[i - 1]) & 3][j - 1] + dist[i]);
  }
  cout << dp[p & 3][k] << endl;
  return 0;
}
