#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const long long M = 1e9 + 7;
const long long maxn = 2e5 + 7;
const double eps = 0.00000001;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <typename T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <typename T>
inline T powMM(T a, T b) {
  T ret = 1;
  for (; b; b >>= 1ll, a = (long long)a * a % M)
    if (b & 1) ret = (long long)ret * a % M;
  return ret;
}
struct node {
  int pos;
  int length;
  node(int p, int l) : pos(p), length(l) {}
  bool operator<(const node &A) const {
    if (A.length == length) length < A.length;
    return pos < A.pos;
  }
};
set<node> S;
set<node>::iterator it;
int A[maxn], pre[maxn], suf[maxn];
int main() {
  int i, j, l;
  int n, k;
  int ans = 0;
  scanf("%d%d", &k, &n);
  for (i = 1; i <= n; i++) scanf("%d", &A[i]);
  sort(A + 1, A + 1 + n);
  n--;
  for (i = 1; i <= n; i++) {
    pre[i] = i - 1;
    suf[i] = i + 1;
    A[i] = A[i + 1] - A[i];
    S.insert(node(i, A[i]));
  }
  while (k--) {
    it = S.begin();
    int pos = (*it).pos;
    ans += (*it).length;
    S.erase(it);
    if (pre[pos] != 0) {
      int x = pre[pos];
      S.erase(node(x, A[x]));
      suf[x] = pos;
    }
    if (suf[pos] != n + 1) {
      int x = suf[pos];
      S.erase(node(x, A[x]));
      pre[x] = pos;
    }
    if (pre[pos] != 0 && suf[pos] != n + 1) {
      A[pos] = A[pre[pos]] + A[suf[pos]] - A[pos];
      S.insert(node(pos, A[pos]));
    }
  }
  printf("%d\n", ans);
  return 0;
}
