#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int arr[300004];
long long memo[5005][5005];
int S, L, c1, c2;
long long rec(int a, int b) {
  if (a == S && b == L) return 0;
  long long &res = memo[a][b];
  if (~res) return res;
  res = (1LL << 60);
  int idx = a * c1 + b * c2;
  if (a < S) res = min(res, rec(a + 1, b) + arr[idx + c1 - 1] - arr[idx]);
  if (b < L) res = min(res, rec(a, b + 1) + arr[idx + c2 - 1] - arr[idx]);
  return res;
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = (0); i < (n); i++) scanf("%d", arr + i);
  sort(arr, arr + n);
  c1 = n / k, c2 = c1 + 1;
  L = n % k, S = k - L;
  memset(memo, -1, sizeof(memo));
  cout << rec(0, 0) << endl;
  return 0;
}
