#include <bits/stdc++.h>
using namespace std;
const int MN = 300005, MK = 5005, inf = 1000000005, mod = 1000000007;
const long long INF = 1000000000000000005LL;
long long dp[MK][MK];
int t[MN];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &t[i]);
  sort(t + 1, t + 1 + n);
  int l1 = n / k + 1, l2 = l1 - 1;
  int a = n % k, b = k - (n % k);
  for (int i = 0; i <= a; ++i)
    for (int j = 0; j <= b; ++j) dp[i][j] = INF;
  dp[0][0] = 0LL;
  for (int i = 0; i <= a; ++i)
    for (int j = 0; j <= b; ++j) {
      int idx = i * l1 + j * l2;
      if (i) dp[i][j] = min(dp[i][j], dp[i - 1][j] + t[idx] - t[idx - l1 + 1]);
      if (j) dp[i][j] = min(dp[i][j], dp[i][j - 1] + t[idx] - t[idx - l2 + 1]);
    }
  printf("%lld", dp[a][b]);
}
