#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000, LEN = 5010;
long long n, k, ar[600300], res, len, len1, kol, kol1, dp[LEN][LEN];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> ar[i];
  sort(ar, ar + n);
  len = (n - 1) / k + 1;
  len1 = len - 1;
  kol = (n - 1) % k + 1;
  kol1 = k - kol;
  for (int i = 0; i < LEN; i++)
    for (int j = 0; j < LEN; j++) dp[i][j] = INF;
  dp[0][0] = 0;
  for (int i = 0; i <= kol; i++)
    for (int j = 0; j <= kol1; j++) {
      dp[i + 1][j] =
          min(dp[i + 1][j], dp[i][j] + abs(ar[(i + 1) * len + j * len1 - 1] -
                                           ar[i * len + j * len1]));
      dp[i][j + 1] =
          min(dp[i][j + 1], dp[i][j] + abs(ar[i * len + (j + 1) * len1 - 1] -
                                           ar[i * len + j * len1]));
    }
  cout << dp[kol][kol1];
  return 0;
}
