#include <bits/stdc++.h>
using namespace std;
long long a[500007], dp[5007][5007];
int main() {
  int n, k;
  cin >> n >> k;
  int res = n % k, len = n / k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  sort(a + 1, a + n + 1);
  memset(dp, 0x3f, sizeof dp);
  dp[0][0] = 0;
  for (int i = 1; i <= k; ++i)
    for (int j = 0; j <= res; ++j) {
      dp[i][j] = dp[i - 1][j] + a[i * len + j] - a[(i - 1) * len + j + 1];
      if (j)
        dp[i][j] = min(
            dp[i][j], dp[i - 1][j - 1] + a[i * len + j] - a[(i - 1) * len + j]);
    }
  cout << dp[k][res] << endl;
}
