#include <bits/stdc++.h>
using namespace std;
int n, k, r, l;
int a[300010];
int f[5010][5010];
int Get(int i, int j) { return a[n + 1 - r * i - j] - a[n - r * i - j]; }
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  sort(a + 1, a + n + 1);
  l = n % k, r = n / k;
  for (int i = 0; i <= k; ++i)
    for (int j = 0; j <= l; ++j) f[i][j] = (1 << 31) - 1;
  f[0][0] = a[n] - a[1];
  a[0] = a[1];
  for (int i = 1; i <= k; ++i)
    for (int j = max(0, l - k + i); j <= min(i, l); ++j) {
      if (j) f[i][j] = f[i - 1][j - 1] - Get(i, j);
      f[i][j] = min(f[i][j], f[i - 1][j] - Get(i, j));
    }
  printf("%d\n", f[k][l]);
  return 0;
}
