#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f;
const long long MOD = 1000000007;
const int IT_MAX = 1 << 17;
const int MX = 1000005;
int N, K;
set<pair<int, int> > S;
int p[500010];
int nxt[500010], pre[500010];
int main() {
  scanf("%d%d", &K, &N);
  for (int i = 1; i <= N; i++) scanf("%d", p + i);
  sort(p + 1, p + 1 + N);
  for (int i = 1; i <= N; i++) p[i] = p[i + 1] - p[i];
  --N;
  for (int i = 1; i < N; i++) nxt[i] = i + 1;
  nxt[N] = -1;
  for (int i = 2; i <= N; i++) pre[i] = i - 1;
  pre[1] = -1;
  for (int i = 1; i <= N; i++) S.insert(pair<int, int>(p[i], i));
  int ans = 0;
  for (int i = 1; i <= K; i++) {
    pair<int, int> t = *S.begin();
    S.erase(S.begin());
    if (pre[t.second] == -1 && nxt[t.second] == -1)
      ;
    else if (pre[t.second] == -1) {
      S.erase(S.find(pair<int, int>(p[nxt[t.second]], nxt[t.second])));
      if (nxt[nxt[t.second]] != -1) pre[nxt[nxt[t.second]]] = -1;
    } else if (nxt[t.second] == -1) {
      S.erase(S.find(pair<int, int>(p[pre[t.second]], pre[t.second])));
      if (pre[pre[t.second]] != -1) nxt[pre[pre[t.second]]] = -1;
    } else {
      S.erase(S.find(pair<int, int>(p[nxt[t.second]], nxt[t.second])));
      S.erase(S.find(pair<int, int>(p[pre[t.second]], pre[t.second])));
      p[t.second] = -p[t.second] + p[nxt[t.second]] + p[pre[t.second]];
      pre[t.second] = pre[pre[t.second]];
      nxt[pre[t.second]] = t.second;
      nxt[t.second] = nxt[nxt[t.second]];
      pre[nxt[t.second]] = t.second;
      S.insert(pair<int, int>(p[t.second], t.second));
    }
    ans += t.first;
  }
  printf("%d\n", ans);
  return 0;
}
