#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, l, nb, nc;
  cin >> n >> k;
  l = n / k;
  nc = n % k;
  nb = k - nc;
  vector<long long> a(n), b(n - l + 1), c(n - l), d(n - 1);
  for (__typeof(n) i = 0; i < n; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  for (__typeof(n - 1) i = 0; i < n - 1; ++i) d[i] = a[i + 1] - a[i];
  for (__typeof(l - 1) i = 0; i < l - 1; ++i) b[0] += d[i];
  for (__typeof(n - l + 1) i = 1; i < n - l + 1; ++i)
    b[i] = b[i - 1] - d[i - 1] + d[i + l - 2];
  for (__typeof(n - l) i = 0; i < n - l; ++i) c[i] = b[i] + d[i + l - 1];
  vector<vector<int>> dp(nb + 1, vector<int>(nc + 1));
  for (__typeof(nb) i = 0; i < nb; ++i) dp[i + 1][0] = dp[i][0] + b[i * l];
  for (__typeof(nc) i = 0; i < nc; ++i)
    dp[0][i + 1] = dp[0][i] + c[i * (l + 1)];
  for (__typeof(nb) i = 0; i < nb; ++i)
    for (__typeof(nc) j = 0; j < nc; ++j)
      dp[i + 1][j + 1] = ((dp[i][j + 1] + b[i * l + (j + 1) * (l + 1)]) >
                                  (dp[i + 1][j] + c[(i + 1) * l + j * (l + 1)])
                              ? (dp[i + 1][j] + c[(i + 1) * l + j * (l + 1)])
                              : (dp[i][j + 1] + b[i * l + (j + 1) * (l + 1)]));
  cout << dp[nb][nc] << endl;
  return 0;
}
