#include <bits/stdc++.h>
using namespace std;
const int maxn = 5007;
const int maxc = 3e5 + 7;
long long dp[maxn][maxn];
long long ar[maxc];
int n, k, tp;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> ar[i];
  sort(ar + 1, ar + n + 1);
  int sg = n / k;
  int lg = sg + 1;
  int ns = k - n % k;
  int nl = n % k;
  for (int i = 0; i <= ns; i++)
    for (int j = 0; j <= nl; j++) dp[i][j] = 2e18;
  dp[0][0] = 0;
  for (int i = 0; i <= ns; i++)
    for (int j = 0; j <= nl; j++) {
      int tp = sg * (i - 1) + lg * j;
      int td = sg * i + lg * (j - 1);
      if (i) dp[i][j] = min(dp[i][j], dp[i - 1][j] + ar[tp + sg] - ar[tp + 1]);
      if (j) dp[i][j] = min(dp[i][j], dp[i][j - 1] + ar[td + lg] - ar[td + 1]);
    }
  cout << dp[ns][nl];
  return 0;
}
