#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
const int K = 5005;
const long long INF = 0xfffffffffffffffLL;
int a[N];
long long f[K][K];
int main() {
  int n, k;
  while (scanf("%d%d", &n, &k) + 1) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    sort(a + 1, a + 1 + n);
    int m = n / k, mx = n % k;
    for (int i = 0; i <= k; i++)
      for (int j = 0; j <= mx; j++) f[i][j] = INF;
    f[0][0] = 0;
    for (int i = 0; i < k; i++) {
      for (int j = 0; j <= mx; j++) {
        if (i * m + m + j <= n)
          f[i + 1][j] =
              min(f[i + 1][j], f[i][j] + a[i * m + m + j] - a[i * m + j + 1]);
        if (i * m + m + j + 1 <= n && j + 1 <= mx)
          f[i + 1][j + 1] =
              min(f[i + 1][j + 1],
                  f[i][j] + a[i * m + m + j + 1] - a[i * m + j + 1]);
      }
    }
    printf("%I64d\n", f[k][mx]);
  }
  return 0;
}
