#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10, MAXK = 5005;
long long n, k, a[MAXN], dp[MAXK][MAXK], tmp;
int pos(int up, int lo) { return up * ((n + k - 1) / k) + lo * (n / k); }
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 1; i <= k; i++)
    for (int j = 0; j <= k - n % k; j++) {
      dp[i][j] = 1LL << 50;
      if (j > i) break;
      tmp = pos(i - j, j - 1);
      if (j > 0 && tmp + (n / k) - 1 < n)
        dp[i][j] =
            min(dp[i][j], dp[i - 1][j - 1] + a[tmp + (n / k) - 1] - a[tmp]);
      tmp = pos(i - j - 1, j);
      if (i - j - 1 >= 0 && tmp + ((n + k - 1) / k) - 1 < n)
        dp[i][j] = min(dp[i][j],
                       dp[i - 1][j] + a[tmp + ((n + k - 1) / k) - 1] - a[tmp]);
    }
  cout << dp[k][k - n % k];
}
