#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[300005];
int sz, cnt0, cnt1;
long long d[5005][5005];
const long long INF = 1e18;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < (int)(n); ++i) scanf("%d", a + i);
  sort(a, a + n);
  sz = n / k;
  cnt0 = cnt1 = 0;
  for (int i = 0; i < (int)(k); ++i) {
    int s = (n - i + k - 1) / k;
    if (s == sz)
      ++cnt0;
    else
      ++cnt1;
  }
  for (int i = 0; i < (int)(cnt0 + 1); ++i)
    for (int j = 0; j < (int)(cnt1 + 1); ++j) d[i][j] = INF;
  d[0][0] = 0;
  for (int i = 0; i < (int)(cnt0 + 1); ++i)
    for (int j = 0; j < (int)(cnt1 + 1); ++j) {
      int pos = i * sz + j * (sz + 1);
      if (i != cnt0) {
        d[i + 1][j] = min(d[i + 1][j], d[i][j] + a[pos + sz - 1] - a[pos]);
      }
      if (j != cnt1) {
        d[i][j + 1] = min(d[i][j + 1], d[i][j] + a[pos + sz] - a[pos]);
      }
    }
  cout << d[cnt0][cnt1] << endl;
  return 0;
}
