#include <bits/stdc++.h>
using namespace std;
int N, K, A[300005];
long long D[5005][5005];
int main() {
  scanf("%d %d", &N, &K);
  for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
  sort(A + 1, A + 1 + N);
  int type1 = (N - 1) / K + 1;
  int type2 = (N - K) / K + 1;
  int cnt1 = 0, cnt2 = 0;
  for (int i = 1; i <= K; i++) {
    int t = (N - i) / K + 1;
    if (t == type1)
      cnt1++;
    else
      cnt2++;
  }
  for (int i = 1; i <= K; i++) {
    for (int j = i - cnt2; j <= min(cnt1, i); j++) {
      int k = i - j;
      int now = j * type1 + k * type2;
      if (j == 0) {
        D[i][j] = D[i - 1][j] + A[now] - A[now - type2 + 1];
      } else if (k == 0) {
        D[i][j] = D[i - 1][j - 1] + A[now] - A[now - type1 + 1];
      } else {
        D[i][j] = min(D[i - 1][j] + A[now] - A[now - type2 + 1],
                      D[i - 1][j - 1] + A[now] - A[now - type1 + 1]);
      }
    }
  }
  cout << D[K][cnt1] << endl;
  return 0;
}
