#include <bits/stdc++.h>
using namespace std;
struct p {
  int st, en, d;
};
bool cmp(p a, p b) { return a.d < b.d; }
bool cmp1(p a, p b) { return a.st < b.st; }
p b[500005];
long long dp[5005], dp1[5005], dp2[5005];
int a[500005];
int main() {
  for (int i = 0; i < 5005; i++)
    dp[i] = 100000000000000LL, dp1[i] = 100000000000000LL;
  int k, n;
  cin >> k >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 1; i < n; i++) {
    b[i - 1].st = a[i - 1], b[i - 1].en = a[i], b[i - 1].d = a[i] - a[i - 1];
  }
  sort(b, b + n - 1, cmp);
  sort(b, b + min(3 * k, n - 1), cmp1);
  dp1[1] = b[0].d;
  dp1[0] = 0, dp[0] = 0;
  if (n == 2) {
    cout << dp1[1] << endl;
    return 0;
  }
  for (int i = 1; i < min(n - 1, 3 * k); i++) {
    for (int cnt = 0; cnt <= k; cnt++) {
      if (cnt == 0)
        dp2[cnt] = 0;
      else if (b[i].st == b[i - 1].en) {
        dp2[cnt] = min(dp1[cnt], dp[cnt - 1] + b[i].d);
        if (dp2[cnt] > 100000000000000LL) dp2[cnt] = 100000000000000LL;
      } else {
        dp2[cnt] = min(dp1[cnt], dp1[cnt - 1] + b[i].d);
        if (dp2[cnt] > 100000000000000LL) dp2[cnt] = 100000000000000LL;
      }
    }
    for (int cnt = 0; cnt <= k; cnt++) {
      dp[cnt] = dp1[cnt];
      dp1[cnt] = dp2[cnt];
    }
  }
  cout << dp2[k] << endl;
  return 0;
}
