#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(2 * k, n - 1), cmp1);
  dp1[1] = b[0].d;
  for (int i = 1; i < min(n - 1, 2 * 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);
      }
    }
    for (int i = 0; i < 5005; i++) {
      dp[i] = dp1[i];
      dp1[i] = dp2[i];
    }
  }
  cout << dp2[k] << endl;
}
