#include <bits/stdc++.h>
using namespace std;
long long int b[500005], a[500005];
long long int d[500005], g[500005];
pair<long long int, long long int> c[500005];
bool vs[500005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  long long int n, k;
  scanf("%lld%lld", &k, &n);
  for (int i = 1; i <= n; i++) cin >> b[i];
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &b[i]);
  }
  sort(b + 1, b + n + 1);
  for (int i = 1; i <= n - 1; i++) {
    a[i] = b[i + 1] - b[i];
    c[i] = pair<long long int, long long int>(a[i], i);
  }
  n--;
  if (n * k <= 500000000) {
    d[0] = 1e18;
    for (int j = 1; j <= k; j++) {
      for (int i = 1; i <= n; i++) g[i] = d[i];
      for (int i = 1; i <= n; i++) {
        if (i + 1 < 2 * j) {
          d[i] = 1e18;
          continue;
        }
        d[i] = min(d[i - 1], g[i - 2] + a[i]);
      }
    }
    cout << d[n] << endl;
  } else {
    sort(c + 1, c + n + 1);
    long long int res = 1e18;
    ;
    for (int st = 1; st <= 1000; st++) {
      long long int sum = 0, u = 0;
      for (int i = 0; i <= n; i++) vs[i] = 0;
      for (int j = st; j <= n; j++) {
        if (vs[c[j].second]) continue;
        sum += c[j].first;
        vs[c[j].second - 1] = 1;
        vs[c[j].second + 1] = 1;
        u++;
        if (u == k) break;
      }
      if (u == k) res = min(res, sum);
    }
    cout << res << endl;
  }
  return 0;
}
