#include <bits/stdc++.h>
using namespace std;
inline long long gtmn(long long &a, long long b) {
  if (a > b) a = b;
}
int a[300010];
long long dp[5010][5010];
int main(void) {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  sort(&a[1], &a[n + 1]);
  int sz = n / q, lge = n % q, sml = q - lge;
  memset(dp, 63, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 0; i < q; ++i) {
    for (int j = 0; j <= lge; ++j) {
      int stt = i * sz + j, lsm = q - i;
      if (lsm) {
        gtmn(dp[i + 1][j], dp[i][j] + a[stt + sz] - a[stt + 1]);
      }
      if (j != lge) {
        gtmn(dp[i + 1][j + 1], dp[i][j] + a[stt + sz + 1] - a[stt + 1]);
      }
    }
  }
  printf("%I64d\n", dp[q][lge]);
  return 0;
}
