#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
template <class T>
inline void read(T &x) {
  char c = getchar();
  x = 0;
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
}
template <class T>
inline void rd(T &res) {
  static char ch;
  bool sgn = false;
  while (ch = getchar(), ch < '0' || ch > '9')
    if (ch == '-') sgn = true;
  res = ch - 48;
  while (ch = getchar(), ch >= '0' && ch <= '9') res = res * 10 + ch - 48;
  res = sgn ? -res : res;
}
template <class T>
void Out(T a) {
  if (a < 0) {
    putchar('-');
    a = -a;
  }
  if (a >= 10) Out(a / 10);
  putchar(a % 10 + '0');
}
const int NN = 3e5 + 10;
const int N = 5011;
const long long oo = 0x3f3f3f3f3f3f3f3fLL;
long long a[NN];
long long *dp[N];
int main() {
  int n, k;
  while (~scanf("%d%d", &n, &k)) {
    int p = n / k, q = n % k;
    for (int i = 1; i <= n; i++) rd(a[i]);
    sort(a + 1, a + n + 1);
    int rp = k - q + 1;
    for (int i = 0; i <= q; i++) dp[i] = new long long[rp];
    for (int i = 0; i <= q; i++)
      for (int j = 0; j <= k - q; j++) dp[i][j] = oo;
    dp[0][0] = 0;
    for (int i = 0; i <= q; i++) {
      for (int j = 0; j <= k - q; j++) {
        if (i)
          dp[i][j] = min(dp[i][j], dp[i - 1][j] + a[i * (p + 1) + j * p] -
                                       a[(i - 1) * (p + 1) + j * p + 1]);
        if (j)
          dp[i][j] = min(dp[i][j], dp[i][j - 1] + a[i * (p + 1) + j * p] -
                                       a[i * (p + 1) + (j - 1) * p + 1]);
      }
    }
    Out(dp[q][k - q]), puts("");
  }
  return 0;
}
