#include <bits/stdc++.h>
using namespace std;
int n, k, i, z;
long long a[300100], f[5100][5100];
long long get(int x, int y) {
  if (f[x][y] >= 0) return f[x][y];
  f[x][y] = 1e15;
  int w = x * (z + 1) + y * z;
  if (x > 0) f[x][y] = min(f[x][y], get(x - 1, y) + a[w] - a[w - z]);
  if (y > 0) f[x][y] = min(f[x][y], get(x, y - 1) + a[w] - a[w - z + 1]);
  return f[x][y];
}
int main() {
  scanf("%d %d", &n, &k);
  for (i = 1; i <= n; ++i) cin >> a[i];
  sort(a + 1, a + 1 + n);
  for (i = n; i >= 2; --i) a[i] = abs(a[i] - a[i - 1]);
  a[1] = 0;
  for (i = 2; i <= n; ++i) a[i] += a[i - 1];
  memset(f, -1, sizeof(f));
  f[0][0] = 0;
  z = n / k;
  cout << get(n % k, k - n % k);
}
