#include <bits/stdc++.h>
using namespace std;
const int M = 5101;
const int N = 330000;
const long long oo = 4111111111L;
int n, k;
long long a[N];
long long f[M][M];
int main() {
  while (~scanf("%d%d", &n, &k)) {
    for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
    sort(a + 1, a + n + 1);
    int p = n / k, q = n % k;
    if (n <= k) {
      printf("0\n");
      continue;
    }
    {
      for (int i = 0; i <= k - q; i++) {
        for (int j = 0; j <= q; j++) {
          f[i][j] = oo;
        }
      }
      f[0][0] = 0;
      for (int i = 0; i <= k - q; i++) {
        for (int j = 0; j <= q; j++) {
          if (i)
            f[i][j] = min(f[i][j], f[i - 1][j] + a[i * p + j * (p + 1)] -
                                       a[(i - 1) * p + j * (p + 1) + 1]);
          if (j)
            f[i][j] = min(f[i][j], f[i][j - 1] + a[i * p + j * (p + 1)] -
                                       a[(i)*p + (j - 1) * (p + 1) + 1]);
        }
      }
    }
    printf("%I64d\n", f[k - q][q]);
  }
  return 0;
}
