#include <bits/stdc++.h>
using namespace std;
const int N = 5009;
const long long oo = (long long)(1e15);
int a[(int)(3e5) + 10];
int n, k, m, t, block;
long long dp[N][N];
long long W[(int)(3e5) + 10];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  block = k;
  m = n / k;
  t = n % k;
  W[1] = 0;
  for (int i = 2; i <= n; i++) W[i] = W[i - 1] + (a[i] - a[i - 1]);
  for (int i = 0; i <= block; i++)
    for (int j = 0; j <= t; j++) dp[i][j] = oo;
  dp[0][0] = 0;
  for (int i = 1; i <= block; i++)
    for (int j = 0; j <= min(i, t); j++) {
      dp[i][j] = dp[i - 1][j] + W[i * m + j] - W[(i - 1) * m + j + 1];
      if (j != 0)
        dp[i][j] =
            min(dp[i][j], dp[i - 1][j - 1] + W[i * m + j] - W[(i - 1) * m + j]);
    }
  cout << dp[block][t] << endl;
}
