#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int N, K, a[300010], dp[5010][5010];
int main() {
  N = read(), K = read();
  for (int i = 1; i <= N; i++) a[i] = read();
  sort(a + 1, a + N + 1);
  int sz1 = N % K, sz2 = K - N % K, len1 = N / K + 1, len2 = N / K;
  a[0] = a[1];
  for (int i = 0; i <= sz1; i++)
    for (int j = 0, k; j <= sz2; j++)
      k = (i - 1) * len1 + j * len2,
      dp[i][j] =
          max(dp[i][j], (i ? (dp[i - 1][j] + a[k + 1] - a[k]) : dp[i][j])),
      k = i * len1 + (j - 1) * len2,
      dp[i][j] =
          max(dp[i][j], (j ? (dp[i][j - 1] + a[k + 1] - a[k]) : dp[i][j]));
  printf("%d\n", a[N] - a[1] - dp[sz1][sz2]);
  return 0;
}
