#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool smin(T &a, const T &b) {
  return b < a ? a = b, 1 : 0;
}
template <typename T>
inline bool smax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const long long N = 3e5 + 10, maxK = 5000 + 10;
long long n, ar[N], dp[maxK][maxK], k;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  memset(dp, 63, sizeof dp);
  cin >> n >> k;
  for (long long i = 1; i <= n; ++i) cin >> ar[i];
  sort(ar + 1, ar + n + 1);
  long long maxBig = n % k, sizeBig = (n + k - 1) / k;
  long long maxSmall = k - maxBig, sizeSmall = (n / k);
  dp[0][0] = 0;
  for (long long big = 0; big <= maxBig; ++big) {
    for (long long small = 0; small <= maxSmall; ++small) {
      if (big + small == 0) continue;
      long long cur = big * sizeBig + small * sizeSmall;
      if (big) {
        long long prv = (big - 1) * sizeBig + small * sizeSmall + 1;
        smin(dp[big][small], ar[cur] - ar[prv] + dp[big - 1][small]);
      }
      if (small) {
        long long prv = (big * sizeBig) + (small - 1) * sizeSmall + 1;
        smin(dp[big][small], ar[cur] - ar[prv] + dp[big][small - 1]);
      }
    }
  }
  cout << dp[maxBig][maxSmall] << '\n';
}
