#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15 + 9;
const double pi = M_PI;
const double ep = 1e-9;
long long a[300002];
long long d[5002][5002];
int main() {
  int n, k, m, A, B;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  m = n / k;
  A = n % k;
  B = k - A;
  for (int i = 0; i <= A; i++)
    for (int j = 0; j <= B; j++) d[i][j] = inf;
  d[0][0] = 0;
  for (int i = 0; i <= A; i++)
    for (int j = 0; j <= B; j++) {
      int u = i * (m + 1) + j * m;
      long long t;
      if (i < A) {
        t = (long long)d[i][j] + a[u + m + 1] - a[u + 1];
        if (t < d[i + 1][j]) d[i + 1][j] = t;
      }
      if (j < B) {
        t = (long long)d[i][j] + a[u + m] - a[u + 1];
        if (t < d[i][j + 1]) d[i][j + 1] = t;
      }
    }
  cout << d[A][B];
  return 0;
}
