#include <bits/stdc++.h>
using namespace std;
long long v[300000];
long long acc[300000];
long long pd[5001][5001];
int len_s, n_big, n_small;
long long solve(int ns, int nb) {
  if (ns + nb == 0) {
    return 0;
  }
  long long& ans = pd[ns][nb];
  if (ans != -1) {
    return ans;
  }
  int p = (n_small - ns) * len_s + (n_big - nb) * (len_s + 1);
  ans = LLONG_MAX;
  if (ns) {
    ans = acc[p + len_s - 1] - acc[p] + solve(ns - 1, nb);
  }
  if (nb) {
    ans = min(ans, acc[p + len_s] - acc[p] + solve(ns, nb - 1));
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  if (n < k) {
    cout << 0 << endl;
    return 0;
  }
  sort(v, v + n);
  for (int i = 1; i < n; ++i) {
    acc[i] = acc[i - 1] + v[i] - v[i - 1];
  }
  len_s = (n - 1) / k;
  n_big = (n - 1 - len_s * k) + 1;
  n_small = k - n_big;
  memset(pd, -1, sizeof pd);
  cout << solve(n_small, n_big) << endl;
  return 0;
}
