#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010;
int a[maxn];
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
long long d[5010][5010];
int n1, n2, t1, t2;
long long dp(int i, int j) {
  if (i == 0 && j == 0) return 0;
  long long &ans = d[i][j];
  if (ans != -1) return ans;
  ans = INF;
  if (i > 0)
    ans = min(ans,
              dp(i - 1, j) + a[i * t1 + j * t2] - a[(i - 1) * t1 + j * t2 + 1]);
  if (j > 0)
    ans = min(ans,
              dp(i, j - 1) + a[i * t1 + j * t2] - a[i * t1 + (j - 1) * t2 + 1]);
  return ans;
}
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  sort(a + 1, a + n + 1);
  a[0] = 0;
  n1 = n % k, n2 = k - n % k, t1 = n / k + 1, t2 = n / k;
  memset(d, -1, sizeof d);
  printf("%lld\n", dp(n1, n2));
  return 0;
}
