#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> A[500000];
long long paixu(long long a[], long long low, long long high) {
  long long key = a[low];
  long long temp;
  while (low < high) {
    while ((low < high) && (a[high] >= key)) {
      high--;
    }
    if (a[high] < key) {
      a[low] = a[high];
      low++;
    }
    while ((low < high) && (a[low] <= key)) {
      low++;
    }
    if (a[low] > key) {
      a[high] = a[low];
      high--;
    }
  }
  a[low] = key;
  return low;
}
void quicksort(long long a[], long long start, long long end) {
  long long pos;
  if (start < end) {
    pos = paixu(a, start, end);
    quicksort(a, start, pos - 1);
    quicksort(a, pos + 1, end);
  }
}
long long x[500010];
long long v[50010];
long long dp[4][50010];
bool e[500010];
int main(int argc, char** argv) {
  long long i;
  long long n, out = 0, sub, num;
  long long y, z;
  cin >> num;
  cin >> n;
  long long p = 0;
  for (i = 1; i <= n; i++) {
    cin >> x[i];
  }
  sort(x + 1, x + 1 + n);
  for (i = 1; i < n; i++) {
    sub = x[i + 1] - x[i];
    A[i].first = sub;
    A[i].second = i;
    v[i] = sub;
  }
  sort(A + 1, A + n);
  memset(dp, 100, sizeof(dp));
  for (int i = 0; i < 4; dp[i++][0] = 0)
    ;
  for (i = 1; i <= min(3 * num, n); i++) {
    e[A[i].second] = 1;
  }
  for (i = 1; i < n; i++) {
    if (e[i] != 1) {
      continue;
    }
    p++;
    for (z = 1; z <= num; z++) {
      dp[p & 3][z] =
          min(dp[(p - 1) & 3][z], dp[(p - 1 - e[i - 1]) & 3][z - 1] + v[i]);
    }
  }
  cout << dp[p & 3][num];
  return 0;
}
