#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e16;
const long long MOD = 1e15 + 9;
const int MX = 500015;
int m, n;
pair<int, int> p[MX];
bool cmp(pair<int, int> p1, pair<int, int> p2) {
  return (p1.second - p1.first < p2.second - p2.first);
}
int a[MX];
int dp[3][15008];
void clr(int cur) {
  for (int i = 0; i <= 15005; i++) {
    dp[cur][i] = 1e9;
  }
}
int main() {
  cin >> m >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 0; i < n - 1; i++) {
    p[i] = {a[i], a[i + 1]};
  }
  sort(p, p + n - 1, cmp);
  int k = min(n - 1, 3 * m);
  sort(p, p + k);
  int cur = 0;
  clr(1);
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < k; i++) {
      if (i) dp[cur][i] = min(dp[cur][i], dp[cur][i - 1]);
      if (dp[cur][i] == 1e9) continue;
      if (p[i + 1].first == p[i].second)
        dp[cur ^ 1][i + 2] =
            min(dp[cur ^ 1][i + 2], dp[cur][i] + (p[i].second - p[i].first));
      else
        dp[cur ^ 1][i + 1] =
            min(dp[cur ^ 1][i + 1], dp[cur][i] + (p[i].second - p[i].first));
    }
    clr(cur);
    cur ^= 1;
  }
  int res = 1e9;
  for (int i = 0; i < k + 2; i++)
    if (dp[cur][i] != -1) res = min(res, dp[cur][i]);
  cout << res;
}
