#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <typename T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
template <typename T>
T inf;
template <>
constexpr int inf<int> = 1e9;
template <>
constexpr ll inf<ll> = 1e18;
template <>
constexpr ld inf<ld> = 1e30;
struct yes_no : numpunct<char> {
  string_type do_truename() const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};
int N, K;
int A[501000];
int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha;
  cout.imbue(loc);
  scanf("%d%d", &K, &N);
  for (int i = 0; i < (int)(N); i++) scanf("%d", &A[i]);
  sort(A, A + N);
  set<pair<ll, ll>> index_value, value_index;
  for (int i = 0; i < (int)(N - 1); i++) {
    const int val = A[i + 1] - A[i];
    index_value.emplace(i, val);
    value_index.emplace(val, i);
  }
  index_value.emplace(-1, inf<ll>);
  index_value.emplace(N, inf<ll>);
  value_index.emplace(inf<ll>, -1);
  value_index.emplace(inf<ll>, N);
  ll res = 0;
  for (int loop = 0; loop < (int)(K); loop++) {
    int v, l, r;
    ll val, lval, rval;
    tie(val, v) = *begin(value_index);
    auto it = index_value.lower_bound(make_pair(v, val));
    tie(l, lval) = *prev(it);
    tie(r, rval) = *next(it);
    index_value.erase(make_pair(v, val));
    index_value.erase(make_pair(l, lval));
    index_value.erase(make_pair(r, rval));
    value_index.erase(make_pair(val, v));
    value_index.erase(make_pair(lval, l));
    value_index.erase(make_pair(rval, r));
    index_value.emplace(v, lval + rval - val);
    value_index.emplace(lval + rval - val, v);
    res += val;
  }
  cout << res << endl;
  return 0;
}
