#include <bits/stdc++.h>
using namespace std;
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }
const long long int MAXN = 3e5 + 10;
long long int a[MAXN];
const long long int MAXK = 5003;
long long int dp[MAXK][MAXK];
long long int large, small, lar_len, small_len;
long long int rec(long long int l, long long int second) {
  if (l > large || second > small) return 1e15;
  if (l == large && second == small) return 0;
  long long int &ans = dp[l][second];
  if (ans != -1) return ans;
  ans = 1e15;
  long long int curr = lar_len * l + small_len * second + 1;
  ans = min(ans, rec(l + 1, second) + a[curr + lar_len - 1] - a[curr]);
  ans = min(ans, rec(l, second + 1) + a[curr + small_len - 1] - a[curr]);
  return ans;
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  for (long long int i = (1); i <= (n); ++i) cin >> a[i];
  sort(a + 1, a + n + 1);
  large = n % k, small = k - n % k;
  lar_len = n / k + 1, small_len = n / k;
  memset((dp), -1, sizeof((dp)));
  cout << rec(0, 0) << '\n';
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t;
  t = 1;
  for (long long int i = (1); i <= (t); ++i) {
    solve();
  }
}
