#include <bits/stdc++.h>
using namespace std;
int read() {
  int re = 0;
  char ch = '!';
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    re = re * 10 + ch - '0';
    ch = getchar();
  }
  return re;
}
const int MAXN = 1e6 + 7;
int n, k, k1, k2, siz;
long long a[MAXN];
long long f[5001][5001];
int main() {
  memset(f, 0x3f, sizeof(f));
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  k1 = n % k;
  k2 = k - k1;
  siz = n / k + 1;
  f[0][0] = 0;
  for (int i = 0; i <= k1; i++) {
    for (int j = 0; j <= k2; j++) {
      if (i)
        f[i][j] = min(f[i][j], f[i - 1][j] + a[i * siz + j * (siz - 1)] -
                                   a[(i - 1) * siz + j * (siz - 1) + 1]);
      if (j)
        f[i][j] = min(f[i][j], f[i][j - 1] + a[i * siz + j * (siz - 1)] -
                                   a[i * siz + (j - 1) * (siz - 1) + 1]);
    }
  }
  cout << f[k1][k2] << endl;
}
