#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5, maxk = 5555;
long long a[maxn], f[maxk][maxk];
int l1, l2, n1, n2, n, k;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%I64d", &a[i]);
  sort(a, a + n);
  f[0][0] = 0;
  l1 = (n - 1) / k + 1;
  l2 = l1 - 1;
  n1 = n - (l1 - 1) * k;
  n2 = k - n1;
  for (int i = 1; i <= n1; i++) {
    f[i][0] = f[i - 1][0] + a[i * l1 - 1] - a[(i - 1) * l1];
  }
  for (int i = 1; i <= n2; i++) {
    f[0][i] = f[0][i - 1] + a[i * l2 - 1] - a[(i - 1) * l2];
  }
  for (int i = 1; i <= n1; i++)
    for (int j = 1; j <= n2; j++)
      f[i][j] =
          a[i * l1 + j * l2 - 1] + min(f[i - 1][j] - a[(i - 1) * l1 + j * l2],
                                       f[i][j - 1] - a[i * l1 + (j - 1) * l2]);
  printf("%I64d\n", f[n1][n2]);
  return 0;
}
