#include <bits/stdc++.h>
using namespace std;
int n, k;
int sz;
long long int a[312345];
int main() {
  scanf("%d %d", &n, &k);
  sz = n / k;
  int L = n % k;
  int S = k - L;
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  sort(a + 1, a + 1 + n);
  map<pair<int, int>, long long int> m;
  map<pair<int, int>, long long int>::iterator mi;
  m[make_pair(1, 0)] = 0;
  long long int ans = 1e18;
  ans += 5;
  while (m.size()) {
    int pos = m.begin()->first.first;
    int l = m.begin()->first.second;
    int s = (pos - l * (sz + 1) - 1) / sz;
    long long int cost = m.begin()->second;
    m.erase(m.begin());
    if (pos == n + 1) {
      ans = min(ans, cost);
      continue;
    }
    if (l < L) {
      int ll = l + 1, ss = s;
      int pp = pos + sz + 1;
      pair<int, int> x = make_pair(pp, ll);
      mi = m.find(x);
      if (mi == m.end())
        m[x] = cost + (a[pp - 1] - a[pos]);
      else
        mi->second = min(mi->second, cost + (a[pp - 1] - a[pos]));
    }
    if (s < S) {
      int ll = l, ss = s + 1;
      int pp = pos + sz;
      pair<int, int> x = make_pair(pp, ll);
      mi = m.find(x);
      if (mi == m.end())
        m[x] = cost + (a[pp - 1] - a[pos]);
      else
        mi->second = min(mi->second, cost + (a[pp - 1] - a[pos]));
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
