#include <bits/stdc++.h>
using namespace std;
int n, k;
long long arr[3 * 100005];
long long dp[5005][5005];
long long Sum(int in, int f) {
  int lm = n / k;
  if (f == 0) lm++;
  return arr[in + lm - 1] - arr[in];
}
long long solve(int g1, int g2) {
  if (g1 == 0 && g2 == 0) {
    return 0;
  }
  if (dp[g1][g2] != -1) return dp[g1][g2];
  long long sum1 = (1LL << 63) - 1;
  long long sum2 = (1LL << 63) - 1;
  int ci = n - (g1 * (n / k + 1) + g2 * (n / k));
  if (g1 > 0) {
    sum1 = Sum(ci, 0);
    sum1 += solve(g1 - 1, g2);
  }
  if (g2 > 0) {
    sum2 = Sum(ci, 1);
    sum2 += solve(g1, g2 - 1);
  }
  return dp[g1][g2] = (sum2 <= sum1 ? sum2 : sum1);
}
int main() {
  cin >> n >> k;
  int md = n % k;
  int g1 = md, g2 = k - md;
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  memset((dp), -1, sizeof((dp)));
  cout << solve(g1, g2) << endl;
  return 0;
}
