#include <bits/stdc++.h>
using namespace std;
struct cho {
  int ti, a;
} chos[500050];
struct po {
  int l, p;
};
int k, n, a[500050], chon = 0, ans = 100000000, fwd[500050];
set<pair<int, int>> inq;
map<pair<int, int>, int> dp;
int main() {
  cin >> k >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  chon = 1;
  chos[0].a = chos[0].ti = -1;
  for (int i = 1; i < n; i++) {
    int cur = a[i] - a[i - 1];
    while (chos[chon - 1].ti >= cur) chon -= 1;
    chos[chon].a = i;
    chos[chon].ti = cur;
    fwd[chos[chon].a] = chos[chon - 1].a;
    chon += 1;
  }
  for (int i = n; i < n + 20; i++) {
    fwd[i] = n - 1;
  }
  for (int i = 0; i < n; i++) {
  }
  queue<po> q;
  q.push((po){n + 1, 0});
  inq.insert(make_pair(n + 1, 0));
  dp[make_pair(n + 1, 0)] = -100000000;
  while (!q.empty()) {
    po cup = q.front();
    q.pop();
    inq.erase(make_pair(cup.l, cup.p));
    if (cup.p == k) {
      ans = min(ans, dp[make_pair(cup.l, cup.p)]);
      continue;
    }
    for (int i = cup.l - 2; i > 0; i = fwd[i]) {
      if (dp[make_pair(i, cup.p + 1)] >
          dp[make_pair(cup.l, cup.p)] + (a[i] - a[i - 1])) {
        dp[make_pair(i, cup.p + 1)] =
            dp[make_pair(cup.l, cup.p)] + (a[i] - a[i - 1]);
        if (!inq.count(make_pair(i, cup.p + 1))) {
          q.push((po){i, cup.p + 1});
        }
      }
    }
  }
  cout << ans + 100000000 << endl;
  return 0;
}
