#include <bits/stdc++.h>
using namespace std;
int ofs[300005];
int cnt[300005];
vector<int> sol[300005];
int vals[300005];
int n, k;
int gr;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &vals[i]);
  sort(vals + 1, vals + 1 + n);
  for (int i = 1; i <= n; i++) {
    ofs[i] = -1;
    cnt[i] = 0;
  }
  ofs[0] = 0;
  cnt[0] = 1;
  sol[0].push_back(0);
  gr = n / k;
  for (int i = 0; i <= n; i++) {
    if (ofs[i] == -1) continue;
    if (i + gr > n) continue;
    for (int j = 0; j < cnt[i]; j++) {
      if (ofs[i] + j + 1 > k) continue;
      for (int t = i + gr; t <= i + gr + (n % k > 0); t++) {
        if (ofs[t] == -1) ofs[t] = ofs[i] + 1;
        int ncn = ofs[i] + j + 2 - ofs[t];
        for (int k = cnt[t]; k < ncn; k++) sol[t].push_back(((1 << 31) - 1));
        cnt[t] = max(cnt[t], ncn);
        sol[t][ofs[i] + j + 1 - ofs[t]] = min(
            sol[t][ofs[i] + j + 1 - ofs[t]], sol[i][j] + vals[t] - vals[i + 1]);
      }
    }
  }
  printf("%d\n", sol[n][k - ofs[n]]);
}
