#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 300005;
const int MAX_K = 5005;
int dp[MAX_K][MAX_K];
int v[MAX_N];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int a = n % k;
  int b = k - n % k;
  int sza = n / k, szb = n / k;
  if (n % k != 0) sza++;
  for (int i = 1; i <= n; ++i) scanf("%d", &v[i]);
  sort(v + 1, v + n + 1);
  for (int i = 1; i <= a; ++i)
    dp[i][0] = dp[i - 1][0] + v[i * sza] - v[1 + (i - 1) * sza];
  for (int i = 1; i <= b; ++i)
    dp[0][i] = dp[0][i - 1] + v[i * szb] - v[1 + (i - 1) * szb];
  for (int i = 1; i <= a; ++i)
    for (int j = 1; j <= b; ++j)
      dp[i][j] = min(
          dp[i - 1][j] + v[i * sza + j * szb] - v[1 + (i - 1) * sza + j * szb],
          dp[i][j - 1] + v[i * sza + j * szb] - v[1 + (j - 1) * szb + i * sza]);
  printf("%d\n", dp[a][b]);
  return 0;
}
