#include <bits/stdc++.h>
using namespace std;
int n, k, b[1000005], p, q, w, dp[5050][5050];
int abs__(int x) { return x > 0 ? x : -x; }
int main() {
  int i, j;
  memset(dp, -1, 5050 * 5050 * sizeof(int));
  scanf("%d %d ", &n, &k);
  for (i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  sort(b, b + n);
  p = k - n % k;
  q = n % k;
  w = n / k;
  dp[0][0] = 0;
  for (i = 0; i <= k; i++) {
    for (j = 0; j <= k; j++) {
      if (i * w + j * (w + 1) <= 300000) {
        if (dp[i + 1][j] > dp[i][j] + abs(b[i * w + j * (w + 1)] -
                                          b[(i + 1) * w + j * (w + 1) - 1]) ||
            dp[i + 1][j] == -1)
          dp[i + 1][j] = dp[i][j] + abs(b[i * w + j * (w + 1)] -
                                        b[(i + 1) * w + j * (w + 1) - 1]);
        if (dp[i][j + 1] > dp[i][j] + abs(b[i * w + j * (w + 1)] -
                                          b[i * w + (j + 1) * (w + 1) - 1]) ||
            dp[i][j + 1] == -1)
          dp[i][j + 1] = dp[i][j] + abs(b[i * w + j * (w + 1)] -
                                        b[i * w + (j + 1) * (w + 1) - 1]);
      }
    }
  }
  printf("%d", dp[p][q]);
}
