#include <bits/stdc++.h>
using namespace std;
long long int expo(long long int base, long long int exponent,
                   long long int mod) {
  long long int ans = 1;
  while (exponent != 0) {
    if ((exponent & 1) == 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    exponent >>= 1;
  }
  return ans % mod;
}
struct M {
  int a;
  int b;
};
long long int inf = 1000000005;
M sto[500005];
M sto2[500005];
long long int k, n;
bool cmp(M a, M b) { return (a.b - a.a) < (b.b - b.a); }
bool cmp2(M a, M b) { return a.a < b.a; }
long long int dp[2][5005][2];
long long int cnt = 0;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> k >> n;
  int ary[n];
  for (long long int i = 0; i < n; ++i) cin >> ary[i];
  sort(ary, ary + n);
  for (long long int i = 0; i < n - 1; ++i) {
    sto[i].a = ary[i];
    sto[i].b = ary[i + 1];
  }
  sort(sto, sto + n - 1, cmp);
  for (long long int i = 0; i < 3 * k; ++i) {
    if (i >= n - 1) break;
    sto2[i] = sto[i];
    cnt++;
  }
  sort(sto2, sto2 + cnt, cmp2);
  for (long long int i = 0; i < 2; ++i) {
    for (long long int j = 0; j < k + 1; ++j) {
      dp[i][j][0] = dp[i][j][1] = inf;
      dp[i][0][0] = 0;
      dp[i][0][0] = 0;
    }
  }
  long long int p = 0;
  long long int ans = inf;
  for (long long int i = 0; i < cnt; ++i) {
    for (long long int j = 1; j < k + 1; ++j) {
      if ((p > 0) && sto2[p].a == sto2[p - 1].b) {
        dp[1][j][1] = dp[0][j - 1][0] + sto2[p].b - sto2[p].a;
      } else {
        dp[1][j][1] =
            min(dp[0][j - 1][1], dp[0][j - 1][0]) + sto2[p].b - sto2[p].a;
      }
      dp[1][j][0] = min(dp[0][j][1], dp[0][j][0]);
    }
    ans = min(ans, min(dp[1][k][0], dp[1][k][1]));
    for (long long int j = 1; j < k + 1; ++j) {
      dp[0][j][1] = dp[1][j][1];
      dp[0][j][0] = dp[1][j][0];
    }
    p++;
  }
  cout << ans << endl;
  return 0;
}
