#include <bits/stdc++.h>
using namespace std;
const int maxk = 5005;
const int maxn = 300005;
const long long huge = 10000000000000000LL;
int n, k;
int a[maxn];
long long dp[maxk][maxk];
long long pref[maxn];
int main(void) {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  for (int i = 1; i <= n; i++) {
    pref[i] = pref[i - 1];
    if (i > 1) pref[i] += a[i - 1] - a[i - 2];
  }
  int cnt1 = 0;
  int cnt2 = 0;
  int len1 = (n - 1) / k + 1;
  int len2 = (n - 1) / k;
  for (int i = 0; i < k; i++) {
    int cnt = 0;
    for (int j = i; j < n; j += k) cnt++;
    if (cnt == len1)
      cnt1++;
    else
      cnt2++;
  }
  for (int i = 0; i <= cnt1; i++)
    for (int j = 0; j <= cnt2; j++) dp[i][j] = huge;
  dp[0][0] = 0;
  for (int i = 0; i <= cnt1; i++)
    for (int j = 0; j <= cnt2; j++) {
      if (i == cnt1 && j == cnt2) {
        printf("%lld\n", dp[i][j]);
        continue;
      }
      if (dp[i][j] == huge) continue;
      int pos = i * len1 + j * len2 + 1;
      dp[i + 1][j] =
          min(dp[i + 1][j], dp[i][j] + pref[pos + len1 - 1] - pref[pos]);
      dp[i][j + 1] =
          min(dp[i][j + 1], dp[i][j] + pref[pos + len2 - 1] - pref[pos]);
    }
  return 0;
}
