#include <bits/stdc++.h>
using namespace std;
const int INF = 1e18;
const int maxk = 5005;
const int maxn = 3e5 + 10;
long long dp[maxk][maxk];
long long arr[maxn];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  for (int i = 0; i < maxk; i++) {
    for (int j = 0; j < maxk; j++) {
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;
  for (int i = 0; i <= k - (n % k); i++) {
    for (int j = 0; j <= n % k; j++) {
      int now = i * (n / k) + j * ((n + k - 1) / k) - 1;
      if (i == 0 && j == 0) {
        dp[i][j] = 0;
        continue;
      }
      long long first = INF, second = INF;
      if (i >= 1) {
        first = arr[now] - arr[now - n / k + 1] + dp[i - 1][j];
      }
      if (j >= 1) {
        second = arr[now] - arr[now - ((n + k - 1) / k) + 1] + dp[i][j - 1];
      }
      dp[i][j] = min(first, second);
    }
  }
  cout << dp[k - (n % k)][n % k];
  return 0;
}
