#include <bits/stdc++.h>
int max;
int f(int k, int n, int* tab);
int f(int k, int n, int* tab) {
  if (k == 0) return 0;
  if (tab[0] > max) return 1e9;
  int lib = n - 2 * k + 2;
  int total = tab[0] + f(k - 1, n - 2, tab + 2);
  int temp;
  for (int i = 1; i < lib; i++) {
    temp = tab[i] + f(k - 1, n - i - 2, tab + 2 + i);
    if (temp < total) total = temp;
  }
  return total;
}
int main(void) {
  int k, n;
  std::cin >> k >> n;
  int tab[n];
  for (int i = 0; i < n; i++) {
    std::cin >> tab[i];
  }
  std::sort(tab, tab + n);
  int diff[n - 1], diff2[n - 1];
  for (int i = 0; i < n - 1; i++) diff[i] = diff2[i] = tab[i + 1] - tab[i];
  std::sort(diff, diff + n - 1);
  if (3 * k < n - 1)
    max = diff[3 * k];
  else
    max = n - 1;
  std::cout << f(k, n - 1, diff);
}
