#include <bits/stdc++.h>
using namespace std;
int arr[3 * 100005];
long long dp[5005][5005];
int mem, low;
int n, k;
long long rec(int full, int kom) {
  if (kom > low) return 10000000000000000ll;
  if (full == k) {
    if (kom == low) return 0;
    return 10000000000000000ll;
  }
  long long& res = dp[full][kom];
  if (res != -1) return res;
  int st = full * mem + kom;
  res = 10000000000000000ll;
  res = min(res, rec(full + 1, kom) + arr[st + mem - 1] - arr[st]);
  res = min(res, rec(full + 1, kom + 1) + arr[st + mem] - arr[st]);
  return res;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  sort(arr, arr + n);
  mem = n / k;
  low = n % k;
  memset(dp, -1, sizeof dp);
  printf("%I64d\n", rec(0, 0));
  return 0;
}
