#include <bits/stdc++.h>
#pragma comment(linker, "/stack:32000000")
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
const long long cinf = 1e18;
const int maxn = 5010;
long long dp[maxn];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int shlen = n / k;
  int llen = (n + k - 1) / k;
  int lcnt = n % k;
  int shcnt = k - lcnt;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  sort(a.begin(), a.end());
  for (int i = 0; i < maxn; ++i) dp[i] = -cinf;
  dp[0] = 0;
  for (int i = 1; i <= k; ++i) {
    for (int j = i; j >= 0; --j) {
      int lst = (i - j) * shlen + j * llen - 1;
      if (lst >= n) continue;
      int st = lst - shlen + 1;
      if (st >= 0) {
        int add = 0;
        if (st > 0) add = a[st] - a[st - 1];
        if (dp[j] != -cinf) dp[j] += add;
      } else
        dp[j] = -cinf;
      if (j) {
        st = lst - llen + 1;
        int add = 0;
        if (st >= 0) {
          if (st > 0) add = a[st] - a[st - 1];
        }
        if (dp[j - 1] != -cinf) dp[j] = max(dp[j], dp[j - 1] + add);
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < n - 1; ++i) ans += a[i + 1] - a[i];
  ans -= dp[lcnt];
  cout << ans << endl;
  return 0;
}
