#include <bits/stdc++.h>
using namespace std;
int n, k;
long long int a[500050], dp[5050][5050];
int main(void) {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  sort(a + 1, a + 1 + n);
  int big = n % k;
  int small = k - big;
  int sblock = n / k, bblock = n / k + 1;
  dp[0][0] = 0;
  for (int i = 1; i <= small; ++i)
    dp[i][0] = dp[i - 1][0] + a[i * sblock] - a[(i - 1) * sblock + 1];
  for (int i = 1; i <= big; ++i)
    dp[0][i] = dp[0][i - 1] + a[i * bblock] - a[(i - 1) * bblock + 1];
  for (int i = 1; i <= small; ++i)
    for (int j = 1; j <= big; ++j)
      dp[i][j] = min(dp[i - 1][j] + a[i * sblock + j * bblock] -
                         a[(i - 1) * sblock + j * bblock + 1],
                     dp[i][j - 1] + a[i * sblock + j * bblock] -
                         a[i * sblock + (j - 1) * bblock + 1]);
  cout << dp[small][big] << endl;
  return 0;
}
