#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000000")
using namespace std;
vector<long long> v;
int a, b, d;
int n, k;
long long memo[5001][5001];
long long f(int first, int second) {
  if (first > a || second > b) return (1LL << 60);
  if (first == a && second == b) return 0;
  long long &ret = memo[first][second];
  if (ret != -1) return ret;
  long long res = (1LL << 60);
  int idx = first * (d + 1) + second * d;
  int idx2 = idx + d - 1;
  res = min(res, v[idx2] - v[idx] + f(first, second + 1));
  idx2 = idx + d;
  if (idx2 < v.size()) {
    res = min(res, v[idx2] - v[idx] + f(first + 1, second));
  }
  return ret = res;
}
int main() {
  memset((memo), (-1), sizeof(memo));
  cin >> n >> k;
  for (int(i) = 0; (i) < (n); (i)++) {
    long long p;
    cin >> p;
    v.push_back(p);
  }
  a = n % k;
  b = k - a;
  d = n / k;
  sort((v).begin(), (v).end());
  cout << f(0, 0) << endl;
}
