#include <bits/stdc++.h>
using namespace std;
const int N = int(3e5) + 10, mod = int(1e9) + 7;
long long d[5005][5005];
int n, k, x[N], sm, lr;
long long calc(int a, int b) {
  if (a == 0 && b == 0) return 0;
  if (d[a][b] != -1) return d[a][b];
  long long res = (long long)(1e18);
  int i = a * lr + b * sm;
  if (a > 0) {
    res = min(res, calc(a - 1, b) + x[i] - x[i - lr + 1]);
  }
  if (b > 0) {
    res = min(res, calc(a, b - 1) + x[i] - x[i - sm + 1]);
  }
  return d[a][b] = res;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x[i]);
  }
  memset(d, -1, sizeof(d));
  sort(x + 1, x + n + 1);
  lr = n / k + 1;
  sm = n / k;
  printf("%lld\n", calc(n % k, k - n % k));
  return 0;
}
