#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5;
int a[MAXN];
int n, k;
long long ans, sum;
void fast_io() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
bool check(int val) {
  int cnt = 0, lst = -1;
  sum = 0;
  for (int i = 1; i < n; i++) {
    if (i - 1 == lst) continue;
    if (a[i] - a[i - 1] > 0 and a[i] - a[i - 1] <= val) {
      sum += (a[i] - a[i - 1]);
      lst = i;
      if (++cnt == k) return 1;
    }
  }
  return 0;
}
int main() {
  fast_io();
  cin >> k >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int lo = 1, hi = 1e9;
  ans = 1e15;
  while (lo <= hi) {
    int mid = (lo + hi) >> 1;
    if (check(mid))
      ans = min(ans, sum), hi = mid - 1;
    else
      lo = mid + 1;
  }
  cout << ans << '\n';
  return 0;
}
