#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  return out << "(" << a.first << ", " << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& v) {
  out << "[";
  for (int i = 0; i < int(int(v.size())); i++) {
    if (i) out << ", ";
    out << v[i];
  }
  return out << "]";
}
mt19937 rnd(time(NULL));
const int INF = int(1e9);
const long long INF64 = long long(1e18);
const int MOD = INF + 7;
const long double EPS = 1e-9;
const long double PI = acos(-1.0);
const int N = 500 * 1000 + 13;
const int K = 5000 + 7;
int n, k;
int a[N];
bool read() {
  if (scanf("%d%d", &k, &n) != 2) return false;
  for (int i = 0; i < int(n); i++) scanf("%d", &a[i]);
  return true;
}
long long calc(set<pair<int, int> >& a) {
  if (int(a.size()) != k) return INF64;
  long long sum = 0;
  for (auto it : a) sum += it.first;
  return sum;
}
void solve() {
  sort(a, a + n);
  set<pair<int, int> > i1, i2, i3;
  long long sum1 = 0, sum2 = 0, sum3 = 0;
  for (int i = int(1); i < int(n); i++) {
    int len = a[i] - a[i - 1];
    if ((int(i2.size()) > int(i1.size())) ||
        (int(i2.size()) == int(i1.size()) && sum2 < sum1)) {
      i3 = i2;
      sum3 = sum2;
    } else {
      i3 = i1;
      sum3 = sum1;
    }
    if (int(i2.size()) < k) {
      i2.insert(make_pair(len, i));
      sum2 += len;
    } else if (i2.rbegin()->first > len) {
      sum2 -= i2.rbegin()->first;
      i2.erase(--i2.end());
      i2.insert(make_pair(len, i));
      sum2 += len;
    }
    i1 = i2;
    sum1 = sum2;
    i2 = i3;
    sum2 = sum3;
  }
  printf("%lld\n", min(calc(i1), calc(i2)));
}
int main() {
  cerr.precision(15);
  cout.precision(15);
  cerr << fixed;
  cout << fixed;
  while (read()) {
    solve();
  }
}
