#include <bits/stdc++.h>
using namespace std;
int Next[500005];
int last[500005];
int forbid[500005];
int pre[500005];
int main() {
  int k, n;
  scanf("%d %d", &k, &n);
  int a[500005];
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  pre[0] = 0;
  pre[1] = 0;
  for (int i = 2; i < n; i++) {
    pre[i] = a[i] - a[i - 1] + pre[i - 2];
  }
  memset(forbid, 0, sizeof(forbid));
  for (int i = 1; i <= n; i++) Next[i] = i + 1;
  for (int i = 1; i <= n; i++) last[i] = i - 1;
  priority_queue<pair<int, pair<int, int> >,
                 vector<pair<int, pair<int, int> > >,
                 greater<pair<int, pair<int, int> > > >
      pq;
  for (int i = 1; i < n; i++) {
    pq.push(make_pair((a[i + 1] - a[i]), (make_pair((i), (i + 1)))));
  }
  int ans = 0;
  for (int i = 0; i < k; i++) {
    while (1) {
      pair<int, pair<int, int> > p = pq.top();
      pq.pop();
      if (!forbid[p.second.first] && !forbid[p.second.second]) {
        ans += p.first;
        int first = last[p.second.first], second = Next[p.second.second];
        forbid[p.second.first] = 1;
        forbid[p.second.second] = 1;
        if (first <= 0 || second > n) break;
        last[second] = first;
        Next[first] = second;
        pq.push(make_pair(
            (a[second] - a[first] - 2 * (pre[second - 1] - pre[first])),
            (make_pair((first), (second)))));
        break;
      }
    }
  }
  printf("%d\n", ans);
}
