#include <bits/stdc++.h>
using namespace std;
vector<vector<long> > dp(5001, vector<long>(5001, -1));
long n, k, x, y, X, Y;
vector<long> A;
long solve(long x, long y) {
  if (dp[x][y] != -1) return dp[x][y];
  long total = x * (n / k) + y * (n / k + 1);
  if (!x)
    dp[x][y] = solve(x, y - 1) + A[total - 1] - A[total - n / k - 1];
  else if (!y)
    dp[x][y] = solve(x - 1, y) + A[total - 1] - A[total - n / k];
  else
    dp[x][y] = min(solve(x - 1, y) + A[total - 1] - A[total - n / k],
                   solve(x, y - 1) + A[total - 1] - A[total - n / k - 1]);
  return dp[x][y];
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    long num;
    cin >> num;
    A.push_back(num);
  }
  dp[0][0] = 0;
  sort(A.begin(), A.end());
  solve(k - n % k, n % k);
  cout << dp[k - n % k][n % k] << endl;
  return 0;
}
