#include <bits/stdc++.h>
using namespace std;
long long a[300005], d[5005][5005];
int main() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + 1 + n);
  long long numl = n % k, nums = k - n % k, l = n / k + 1, s = n / k;
  memset(d, 0x3f, sizeof(d));
  d[0][0] = 0;
  for (long long i = 0; i <= numl; i++) {
    for (long long j = 0; j <= nums; j++) {
      long long x = (i * l + j * s);
      if (i > 0) d[i][j] = min(d[i][j], d[i - 1][j] + a[x] - a[x - l + 1]);
      if (j > 0) d[i][j] = min(d[i][j], d[i][j - 1] + a[x] - a[x - s + 1]);
    }
  }
  cout << d[numl][nums] << endl;
}
