#include <bits/stdc++.h>
using namespace std;
long long dp[5001][5001];
long long a[300005];
int main() {
  int n, k, i, j;
  cin >> n >> k;
  for (i = 0; i <= k; i++)
    for (j = 0; j <= k; j++) dp[i][j] = 1e10;
  for (i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  int small, large, sizesmall, sizelarge;
  sizesmall = n / k;
  sizelarge = n / k + 1;
  large = n % k;
  small = k - n % k;
  dp[0][0] = 0;
  for (i = 0; i <= small; i++) {
    for (j = 0; j <= large; j++) {
      if (i > 0) {
        int index = (i - 1) * sizesmall + j * sizelarge;
        dp[i][j] =
            min(dp[i][j], dp[i - 1][j] + a[index + sizesmall] - a[index + 1]);
      }
      if (j > 0) {
        int index = i * sizesmall + (j - 1) * sizelarge;
        dp[i][j] =
            min(dp[i][j], dp[i][j - 1] + a[index + sizelarge] - a[index + 1]);
      }
    }
  }
  cout << dp[small][large];
}
