#include <bits/stdc++.h>
using namespace std;
int n, k, n1, n2, alpha;
long long a[300003];
long long dp[5005][5005];
long long memo(int need, int tp1) {
  int tp2 = (k - need) - tp1;
  if (need == 0) return 0;
  if (dp[need][tp1] != -1) return dp[need][tp1];
  int idx = n - 1 - tp1 * alpha - tp2 * (alpha + 1);
  long long res1 = (long long)(1e15), res2 = (long long)(1e15);
  if (tp1 < n1) {
    int _idx = idx - alpha + 1;
    res1 = min(res1, a[idx] - a[_idx] + memo(need - 1, tp1 + 1));
  }
  if (tp2 < n2) {
    int _idx = idx - alpha;
    res2 = min(res2, a[idx] - a[_idx] + memo(need - 1, tp1));
  }
  return dp[need][tp1] = min(res1, res2);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(dp, -1, sizeof dp);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  long long ans = 0;
  alpha = n / k;
  n2 = n - (n / k) * k;
  n1 = k - n2;
  cout << memo(k, 0) << '\n';
  return 0;
}
