#include <bits/stdc++.h>
using namespace std;
long long n, k, dp[5005][5005], sizek, num, a[500005];
int main() {
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sizek = n / k;
  num = n % k;
  sort(a + 1, a + 1 + n);
  for (int i = 0; i <= 5000; i++) {
    for (int j = 0; j <= 5000; j++) dp[i][j] = LLONG_MAX;
  }
  dp[0][0] = 0;
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j <= num; j++) {
      long long posy = i * sizek + j, posx = (i - 1) * sizek + 1 + j,
                posy1 = (i - 1) * sizek + j;
      if (dp[i - 1][j] != LLONG_MAX)
        dp[i][j] = dp[i - 1][j] + a[posy] - a[posx];
      if (j && dp[i - 1][j - 1] != LLONG_MAX)
        dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + a[posy] - a[posy1]);
    }
  }
  cout << dp[k][num];
}
