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