#include <bits/stdc++.h>
using namespace std;
const long long maxN = 5e3 + 13, INF = 1e18 + 13;
long long n, k, dp[maxN][maxN];
vector<long long> vec;
int32_t main() {
  cin >> n >> k;
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    vec.push_back(a);
  }
  memset(dp, 63, sizeof dp);
  sort(vec.begin(), vec.end());
  long long s = k - (n % k), l = n % k;
  for (long long i = 0; i <= s; i++)
    for (long long j = 0; j <= l; j++) {
      if (i == 0 && j == 0)
        dp[i][j] = 0;
      else
        dp[i][j] = min(
            ((i) ? dp[i - 1][j] +
                       vec[(i - 1) * (n / k) + j * (n / k + 1) + n / k - 1] -
                       vec[(i - 1) * (n / k) + j * (n / k + 1)]
                 : INF),
            ((j) ? dp[i][j - 1] +
                       vec[i * (n / k) + (j - 1) * (n / k + 1) + n / k] -
                       vec[i * (n / k) + (j - 1) * (n / k + 1)]
                 : INF));
    }
  cout << dp[s][l] << endl;
}
