#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
const int NMax = 5e5 + 5;
const ll inf_ll = 1e18 + 5;
const int inf_int = 1e9 + 5;
const int mod = 100003;
using zint = int;
ll sum[NMax];
multiset<ll, greater<ll> > heap[NMax];
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  ll N, K;
  cin >> K >> N;
  vector<ll> v(N + 1);
  for (ll i = 1; i <= N; ++i) {
    cin >> v[i];
  }
  sort(v.begin() + 1, v.end());
  if (N == 2) {
    cout << v[2] - v[1];
    return 0;
  }
  if (N == 3) {
    cout << min(v[3] - v[2], v[2] - v[1]);
    return 0;
  }
  heap[2].insert(v[2] - v[1]);
  sum[2] = v[2] - v[1];
  heap[3].insert(v[3] - v[2]);
  sum[3] = v[3] - v[2];
  if (sum[2] < sum[3]) {
    heap[3] = heap[2];
    sum[3] = sum[2];
  }
  for (ll i = 2; i <= N; ++i) {
    ll dif = v[i] - v[i - 1];
    ll num1, val1, num2, val2;
    num1 = heap[i - 1].size();
    val1 = sum[i - 1];
    num2 = ((heap[i - 2].size() == K) ? K : heap[i - 2].size() + 1);
    if (heap[i - 2].size() < K) {
      val2 = sum[i - 2] + dif;
    } else {
      val2 = sum[i - 2];
      if (*(heap[i - 2].begin()) > dif) {
        val2 += -*(heap[i - 2].begin()) + dif;
      }
    }
    if (num1 > num2 || num1 == num2 && val1 <= val2) {
      heap[i] = heap[i - 1];
      sum[i] = sum[i - 1];
    } else {
      sum[i] = val2;
      heap[i] = heap[i - 2];
      if (heap[i - 2].size() < K) {
        heap[i].insert(dif);
      } else {
        if (*(heap[i].begin()) > dif) {
          heap[i].erase(heap[i].begin());
          heap[i].insert(dif);
        }
      }
    }
  }
  cout << sum[N] << '\n';
  return 0;
}
