#include <bits/stdc++.h>
using namespace std;
const int mx = 3e5 + 5;
long long a[mx];
long long dp[5005][5005];
int main() {
  int n, k, l, l1, l2, tmp;
  long long ans;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  sort(a + 1, a + n + 1);
  memset(dp, 0, sizeof(dp));
  a[0] = 0;
  l1 = n % k;
  l2 = k - l1;
  l = n / k;
  for (int i = 0; i <= l1; i++)
    for (int j = 0; j <= l2; j++) {
      if (i == 0 && j == 0) continue;
      tmp = i * (l + 1) + j * l + 1;
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + a[tmp] - a[tmp - 1]);
      dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + a[tmp] - a[tmp - 1]);
    }
  ans = a[n] - a[1] - dp[l1][l2];
  printf("%I64d\n", ans);
  return 0;
}
