#include <bits/stdc++.h>
using namespace std;
long long MOD = int(1e9) + 7;
int dp[5050][5050];
int debug = 1;
int a[300005];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i < n + 1; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  int lg = n % k;
  int szl = (n / k + 1);
  int szs = (n / k);
  int sml = k - lg;
  for (int i = 0; i < lg + 1; i++) {
    for (int j = 0; j < sml + 1; j++) {
      dp[i][j] = 2000 * 1000 * 1000 + 5;
    }
  }
  dp[0][0] = 0;
  for (int i = 0; i < lg + 1; i++) {
    for (int j = 0; j < sml + 1; j++) {
      int ind = szl * i + szs * j;
      if (j >= 1) {
        dp[i][j] = min(dp[i][j], a[ind] - a[ind - szs + 1] + dp[i][j - 1]);
      }
      if (i >= 1) {
        dp[i][j] = min(dp[i][j], a[ind] - a[ind - szl + 1] + dp[i - 1][j]);
      }
    }
  }
  cout << dp[lg][sml] << endl;
  return 0;
}
