#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int n, m;
struct elem {
  int x, y;
  int data;
};
int arr[1000005];
elem arr2[1000005];
bool used[1000005];
bool cmp(elem a, elem b) {
  return a.data < b.data || (a.data == b.data && a.x < b.x);
}
bool canTake(int x) {
  if (arr2[x].y == arr2[x + 1].x) return true;
  if (arr2[x].x == arr2[x + 1].y) return true;
  if (arr2[x].x == arr2[x + 1].x) return true;
  if (arr2[x].y == arr2[x + 1].y) return true;
  return false;
}
bool canTake2(int x) {
  if (x + 2 >= m) return false;
  if (arr2[x].y == arr2[x + 2].x) return true;
  if (arr2[x].x == arr2[x + 2].y) return true;
  if (arr2[x].x == arr2[x + 2].x) return true;
  if (arr2[x].y == arr2[x + 2].y) return true;
  return false;
}
int dpT[12000][5000];
int obm;
int dp(int ptr, int was) {
  if (was == n) return 0;
  if (ptr >= obm) {
    return 1000000000;
  }
  if (dpT[ptr][was] != 1000000000) return dpT[ptr][was];
  int ans =
      min(dp(ptr + (int)canTake(ptr) + (int)canTake(ptr) * canTake2(ptr) + 1,
             was + 1) +
              arr2[ptr].data,
          dp(ptr + 1, was));
  return dpT[ptr][was] = ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  obm = min(min(m - 1, n * 3), 11999);
  for (int(i) = 0; (i) < (m); (i)++) {
    cin >> arr[i];
  }
  sort(arr, arr + m);
  for (int(i) = 0; (i) < (m - 1); (i)++) {
    arr2[i].data = arr[i + 1] - arr[i];
    arr2[i].x = i;
    arr2[i].y = i + 1;
  }
  int ans = 0;
  sort(arr2, arr2 + m - 1, cmp);
  for (int(i) = (0); (i) < (12000); (i)++) {
    for (int(j) = (0); (j) < (5000); (j)++) {
      dpT[i][j] = 1000000000;
    }
  }
  cout << dp(0, 0);
  return 0;
}
