#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long>> tree(4L * 1000006);
void build(vector<long long> &a, long v, long tl, long tr) {
  if (tl == tr) {
    tree[v] = make_pair(a[tl], tl);
    return;
  }
  long tm = (tl + tr) >> 1;
  build(a, 2L * v, tl, tm);
  build(a, 2L * v + 1, tm + 1, tr);
  if (tree[2L * v].first <= tree[2L * v + 1].first)
    tree[v] = tree[2L * v];
  else
    tree[v] = tree[2L * v + 1];
  return;
}
void update(vector<long long> &a, long long val, long pos, long v, long tl,
            long tr) {
  if (tl == tr) {
    a[pos] = val;
    tree[v] = make_pair(a[pos], pos);
    return;
  }
  long tm = (tl + tr) >> 1;
  if (pos <= tm)
    update(a, val, pos, 2L * v, tl, tm);
  else
    update(a, val, pos, 2L * v + 1, tm + 1, tr);
  if (tree[2L * v].first <= tree[2L * v + 1].first)
    tree[v] = tree[2L * v];
  else
    tree[v] = tree[2L * v + 1];
  return;
}
pair<long long, long> rmq(long lo, long hi, long v, long tl, long tr) {
  if (lo > hi) return make_pair(1000000000000000, -1);
  if (lo == tl && hi == tr) return tree[v];
  long tm = (tl + tr) >> 1;
  pair<long long, long> v1 = rmq(lo, min(hi, tm), 2L * v, tl, tm);
  pair<long long, long> v2 = rmq(max(lo, tm + 1), hi, 2L * v + 1, tm + 1, tr);
  if (v1.first <= v2.first) return v1;
  return v2;
}
int main() {
  long n, k, x;
  cin >> k >> n;
  vector<long> t;
  for (long i = 0; i < n; i++) {
    cin >> x;
    t.push_back(x);
  }
  sort(t.begin(), t.end());
  if (n <= 3 * k) {
    long long dp[n][k + 1];
    for (long i = 0; i < n; i++) {
      dp[i][0] = 1000000000000000;
    }
    for (long i = 0; i < n; i++) {
      for (long j = 1; j <= k; j++) {
        if (i + 1 < 2L * j)
          dp[i][j] = 1000000000000000;
        else if (i == 1)
          dp[i][j] = t[i] - t[i - 1];
        else
          dp[i][j] = min(dp[i - 1][j], t[i] - t[i - 1] + dp[i - 2][j - 1]);
      }
    }
    cout << dp[n - 1][k] << endl;
  } else {
    vector<long long> dif;
    for (long i = 0; i < n - 1; i++) {
      dif.push_back(t[i + 1] - t[i]);
    }
    build(dif, 1L, 0L, n - 2);
    long cnt = 0;
    pair<long long, long> v;
    long long ans = 0LL;
    while (cnt < k) {
      v = tree[1];
      ans += v.first;
      update(dif, 1000000000000000, v.second, 1L, 0L, n - 2);
      if (v.second < n - 2)
        update(dif, 1000000000000000, v.second + 1, 1L, 0L, n - 2);
      if (v.second > 0)
        update(dif, 1000000000000000, v.second - 1, 1L, 0L, n - 2);
      cnt++;
    }
    cout << ans << endl;
  }
}
