#include <bits/stdc++.h>
using namespace std;
const long long maxn = 5e5 + 5;
long long k, n, cnt, cnt2;
long long a[maxn];
struct node {
  long long l, r, w;
  bool operator<(const node &b) const { return w < b.w; }
} cha[maxn];
long long b[maxn];
long long dp[5][5005];
bool vis[maxn];
int main() {
  cin >> k >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  if (k * 4 <= n) {
    for (long long i = 2; i <= n; i++) {
      cha[cnt++] = {i - 1, i, a[i] - a[i - 1]};
    }
    sort(cha, cha + cnt);
    for (long long i = 0; i < 3 * k; i++) {
      vis[cha[i].l] = vis[cha[i].r] = 1;
      if (cha[i].l > 1) vis[cha[i].l - 1] = 1;
      if (cha[i].r < n) vis[cha[i].r + 1] = 1;
    }
    for (long long i = 1; i <= n; i++) {
      if (vis[i]) b[++cnt2] = a[i];
    }
    n = cnt2;
  } else {
    for (long long i = 1; i <= n; i++) b[i] = a[i];
  }
  for (long long i = 0; i <= 3; i++) {
    for (long long j = 1; j <= 5000; j++) {
      dp[i][j] = 4e18;
    }
    dp[i][0] = 0;
  }
  long long ans = 4e18;
  for (long long i = 2, tmp = 2; i <= n; i++) {
    long long lim = min(i / 2, k);
    for (long long j = 1; j <= lim; j++) dp[tmp][j] = 4e18;
    for (long long j = 1; j <= lim; j++) {
      dp[tmp][j] = min(dp[(tmp + 1) % 3][j - 1] + b[i] - b[i - 1], dp[tmp][j]);
      dp[tmp][j] = min(dp[tmp][j], dp[(tmp + 2) % 3][j]);
      if (j == k) ans = min(ans, dp[tmp][k]);
    }
    tmp = (tmp + 1) % 3;
  }
  cout << ans << endl;
  return 0;
}
