#include <bits/stdc++.h>
using namespace std;
template <typename X>
inline X abs(const X& a) {
  return a < 0 ? -a : a;
}
template <typename X>
inline X sqr(const X& a) {
  return a * a;
}
template <typename A, typename B>
inline ostream& operator<<(ostream& out, const pair<A, B>& p) {
  return out << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
inline ostream& operator<<(ostream& out, const vector<T>& a) {
  out << "[";
  for (int i = 0; i < int(int((a).size())); i++) {
    if (i) out << ',';
    out << ' ' << a[i];
  }
  return out << " ]";
}
template <typename T>
inline ostream& operator<<(ostream& out, const set<T>& a) {
  return out << vector<T>((a).begin(), (a).end());
}
template <typename X, typename Y>
inline ostream& operator<<(ostream& out, const map<X, Y>& a) {
  return out << vector<pair<X, Y>>((a).begin(), (a).end());
}
template <typename T>
inline ostream& operator<<(ostream& out, const pair<T*, int>& a) {
  return out << vector<T>(a.first, a.first + a.second);
}
inline long double gett() { return long double(clock()) / CLOCKS_PER_SEC; }
const int INF = int(1e9);
const long long INF64 = long long(1e18);
const long double EPS = 1e-9, PI = 3.1415926535897932384626433832795;
const int N = 500500;
int n, k;
int a[N];
struct Value {
  int answer;
  int cur;
  int next;
};
bool operator<(const Value& a, const Value& b) {
  if (a.answer != b.answer) return a.answer < b.answer;
  if (a.cur != b.cur) return a.cur < b.cur;
  if (a.next != b.next) return a.next < b.next;
  return false;
}
bool operator==(const Value& a, const Value& b) {
  if (a.answer != b.answer) return false;
  if (a.cur != b.cur) return false;
  if (a.next != b.next) return false;
  return true;
}
bool read() {
  if (!(cin >> k >> n)) return false;
  for (int i = 0; i < int(n); i++) assert(scanf("%d", &a[i]) == 1);
  return true;
}
int solve() {
  sort(a, a + n);
  map<int, int> next;
  map<int, int> prev;
  map<int, Value> val;
  map<int, int> ddelta;
  set<pair<int, Value>> z;
  for (int i = 0; i < int(n - 1); i++) {
    int d = a[i + 1] - a[i];
    Value value{0, i, i + 1};
    z.insert(make_pair((d), (value)));
    ddelta[i] = d;
    val[i] = value;
    prev[i + 1] = i;
    next[i] = i + 1;
  }
  prev[0] = -1;
  next[n - 1] = n;
  int result = 0;
  for (int _ = 0; _ < int(k); _++) {
    assert(!z.empty());
    int delta = z.begin()->first;
    assert(delta >= 0);
    int i = z.begin()->second.cur;
    int j = z.begin()->second.next;
    int ans = z.begin()->second.answer;
    assert(delta == ddelta[i]);
    assert(z.begin()->second == val[i]);
    z.erase(z.begin());
    z.erase(make_pair((ddelta[j]), (val[j])));
    result += delta;
    int ni = prev[i], nj = next[j];
    if (ni == -1 || nj == n) continue;
    int ansi = val[ni].answer;
    int ansj = val[j].answer;
    int nans = ansi + ansj + ((a[j] - a[i]) - ans);
    int ndelta = (a[nj] - a[ni]) - 2 * nans;
    assert(ndelta >= 0);
    z.erase(make_pair((ddelta[ni]), (val[ni])));
    Value nval{nans, ni, nj};
    z.insert(make_pair((ndelta), (nval)));
    ddelta[ni] = ndelta;
    val[ni] = nval;
    prev[nj] = ni;
    next[ni] = nj;
  }
  return result;
}
int naive() {
  sort(a, a + n);
  int ans = INF;
  vector<bool> z(n);
  for (int mask = 0; mask < int((1 << n)); mask++) {
    for (int i = 0; i < int(n); i++) z[i] = (mask >> i) & 1;
    int c = 0, b = 0;
    for (int i = 0; i < int(n - 1); i++)
      if (z[i] && z[i + 1]) b = 1;
    for (int i = 0; i < int(n); i++) c += z[i];
    if (c != k) continue;
    if (b || z.back()) continue;
    int cur = 0;
    for (int i = 0; i < int(n); i++)
      if (z[i]) cur += a[i + 1] - a[i];
    ans = min(ans, cur);
  }
  return ans;
}
int main() {
  cout << setprecision(10) << fixed;
  cerr << setprecision(5) << fixed;
  while (read()) {
    long double stime = gett();
    int ans = solve();
    cout << ans << endl;
  }
  return 0;
}
