#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  long long l = n % k, c = k - l, dis = n / k;
  long long d[c + 1][l + 1];
  for (int i = 0; i <= c; i++)
    for (int j = 0; j <= l; j++) d[i][j] = 99999999999;
  d[0][1] = a[n - 1] - a[0];
  d[1][0] = a[n - 1] - a[0];
  for (int i = 0; i <= c; i++)
    for (int j = 0; j <= l; j++) {
      dis = i * (n / k) + j * (n / k + 1);
      if (i + 1 <= c and dis < n and dis > 0)
        d[i + 1][j] = min(d[i + 1][j], d[i][j] - a[dis] + a[dis - 1]);
      if (j + 1 <= l and dis < n and dis > 0)
        d[i][j + 1] = min(d[i][j + 1], d[i][j] - a[dis] + a[dis - 1]);
    }
  cout << d[c][l] << endl;
}
