#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
const int M = 1e9 + 7;
const double eps = 1e-6;
const long long inf = 1e18;
const double PI(acos(-1.0));
int n, m, cnt;
int a[N];
int dp[2][2][5005];
pair<int, int> q[N];
bool vis[N];
int main() {
  scanf("%d%d", &m, &n);
  for (int i = (1); i <= (n); i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  if (n <= 4 * m) {
    memset(dp, 127, sizeof dp);
    dp[0][0][0] = dp[1][0][0] = 0;
    for (int i = (2); i <= (n); i++) {
      for (int j = min(m, i / 2); j >= 1; j--) {
        dp[cnt][0][j] = min(dp[cnt ^ 1][0][j], dp[cnt ^ 1][1][j]);
        dp[cnt][1][j] = dp[cnt ^ 1][0][j - 1] + a[i] - a[i - 1];
      }
      cnt ^= 1;
    }
    printf("%d\n", min(dp[cnt ^ 1][0][m], dp[cnt ^ 1][1][m]));
  } else {
    for (int i = (1); i <= (n - 1); i++) q[i] = make_pair(a[i + 1] - a[i], i);
    sort(q + 1, q + n);
    int sum = 0;
    for (int i = 1; m; i++) {
      if (!vis[q[i].second + 1] && !vis[q[i].second - 1]) {
        vis[q[i].second] = 1;
        sum += q[i].first;
        m--;
      }
    }
    printf("%d", sum);
  }
}
