#include <bits/stdc++.h>
using namespace std;
long long n, k, nex = 1, las;
long long dp[2][5009][2];
pair<long long, long long> a[500005];
bool cmp(pair<long long, long long> x, pair<long long, long long> y) {
  return x.second < y.second;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> k >> n;
  for (long long i = 1; i <= n; ++i) cin >> a[i].first, a[i].second = 0;
  sort(a + 1, a + n + 1);
  for (long long i = 1; i < n; ++i)
    a[i].first = a[i + 1].first - a[i].first, a[i].second = i;
  sort(a + 1, a + n);
  sort(a + 1, a + 2 * k, cmp);
  for (long long j = 0; j <= k; ++j)
    dp[nex][j][0] = dp[las][j][1] = dp[nex][j][1] = dp[las][j][0] =
        10000000000000007;
  dp[0][0][0] = 0;
  for (long long i = 0; i < 2 * k - 1; ++i) {
    for (long long j = 0; j <= k; ++j) {
      if (dp[las][j][0] < 10000000000000007) {
        if (j < k)
          dp[nex][j + 1][1] =
              min(dp[nex][j + 1][1], dp[las][j][0] + a[i + 1].first);
        dp[nex][j][0] = min(dp[nex][j][0], dp[las][j][0]);
      }
      if (dp[las][j][1] < 10000000000000007) {
        dp[nex][j][0] = min(dp[nex][j][0], dp[las][j][1]);
        if (abs(a[i + 1].second - a[i].second) != 1) {
          dp[nex][j + 1][1] =
              min(dp[nex][j + 1][1], dp[las][j][1] + a[i + 1].first);
        }
      }
    }
    swap(las, nex);
    for (long long j = 0; j <= k; ++j)
      dp[nex][j][0] = dp[nex][j][1] = 10000000000000007;
  }
  long long res = min(dp[las][k][0], dp[las][k][1]);
  cout << res;
}
