#include <bits/stdc++.h>
using namespace std;
long long dp[5010][5010];
int a[300010];
int main(void) {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  sort(&a[1], &a[n + 1]);
  int bsz = n / k, lg = n % k, sm = k - lg;
  dp[0][0] = 0;
  for (int i = 0; i <= sm; i++) {
    for (int j = 0; j <= lg; j++) {
      if (!i && !j) continue;
      int sz = i * bsz + j * (bsz + 1);
      if (!i) {
        dp[i][j] = dp[i][j - 1] + a[sz] - a[sz - bsz];
        continue;
      }
      if (!j) {
        dp[i][j] = dp[i - 1][j] + a[sz] - a[sz - bsz + 1];
        continue;
      }
      dp[i][j] = min(dp[i - 1][j] + a[sz] - a[sz - bsz + 1],
                     dp[i][j - 1] + a[sz] - a[sz - bsz]);
    }
  }
  printf("%I64d", dp[sm][lg]);
  return 0;
}
