#include <bits/stdc++.h>
using namespace std;
int k, n, l1, l2, a[300010], del[300010];
int dp[5005][5005];
int solve(int a, int b) {
  if (a == 0 and b == 0) return 0;
  int &ret = dp[a][b];
  if (ret != -1) return ret;
  ret = 0;
  if (a > 0 and b > 0)
    ret = max(solve(a - 1, b), solve(a, b - 1)) + del[a * l1 + b * l2];
  else if (a > 0)
    ret = solve(a - 1, b) + del[a * l1 + b * l2];
  else if (b > 0)
    ret = solve(a, b - 1) + del[a * l1 + b * l2];
  return ret;
}
int main() {
  cin >> n >> k;
  memset(dp, -1, sizeof(dp));
  memset(del, 0, sizeof(del));
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  for (int i = 1; i < n; i++) del[i] = a[i] - a[i - 1];
  l1 = n / k + 1;
  l2 = n / k;
  int ans = solve(n % k, k - n % k);
  ans = a[n - 1] - a[0] - ans;
  printf("%d\n", ans);
  return 0;
}
