#include <bits/stdc++.h>
using namespace std;
int A[300000 + 1];
bool used[5000 + 1][5000 + 1];
long long memo[5000 + 1][5000 + 1];
int n, K;
long long la, lb;
long long ga, gb;
long long dp(int a, int b) {
  if (a == ga && b == gb) return 0;
  if (used[a][b]) return memo[a][b];
  used[a][b] = 1;
  long long &dev = memo[a][b] = (1LL << 60);
  int pos = a * la + b * lb;
  if (a + 1 <= ga) dev = min(dev, A[pos + la - 1] - A[pos] + dp(a + 1, b));
  if (b + 1 <= gb) dev = min(dev, A[pos + lb - 1] - A[pos] + dp(a, b + 1));
  return dev;
}
int main() {
  while (scanf("%d", &n) == 1) {
    scanf("%d", &K);
    for (int i = 0; i < n; i++) scanf("%d", &A[i]);
    la = (n - 1) / K + 1;
    lb = n / K;
    ga = (n % K);
    gb = K - (n % K);
    sort(A, A + n);
    memset(used, 0, sizeof(used));
    cout << dp(0, 0) << '\n';
  }
}
