#include <bits/stdc++.h>
using namespace std;
int ara[300010];
int dp[5010][5010];
int X, Y, x, y;
int solve(int i, int j) {
  if (i == x && j == y) return 0;
  if (dp[i][j] != -1) return dp[i][j];
  int a = 2000000000, b = 2000000000;
  int c = i * X + j * Y;
  if (i + 1 <= x) a = ara[c + X] - ara[c + 1] + solve(i + 1, j);
  if (j + 1 <= y) b = ara[c + Y] - ara[c + 1] + solve(i, j + 1);
  return dp[i][j] = min(a, b);
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> ara[i];
  sort(ara + 1, ara + n + 1);
  X = (n / k) + 1, x = n % k, Y = n / k, y = k - (n % k);
  memset(dp, -1, sizeof dp);
  cout << solve(0, 0) << endl;
}
