#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long int dp[5005][5005];
int main() {
  long long int n, a[300005], k, lg, sg, x;
  scanf("%lld %lld", &n, &k);
  ;
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  sort(a, a + n);
  lg = n % k;
  sg = k - n % k;
  x = n / k;
  for (int i = 1; i <= sg; i++)
    dp[0][i] = dp[0][i - 1] + (a[i * x - 1] - a[(i - 1) * x]);
  for (int i = 1; i <= lg; i++)
    dp[i][0] = dp[i - 1][0] + (a[i * (x + 1) - 1] - a[(i - 1) * (x + 1)]);
  for (int i = 1; i <= lg; i++)
    for (int j = 1; j <= sg; j++)
      dp[i][j] = min(dp[i][j - 1] + (a[i * (x + 1) + (j - 1) * x + x - 1] -
                                     a[i * (x + 1) + (j - 1) * x]),
                     dp[i - 1][j] + (a[(i - 1) * (x + 1) + j * x + x] -
                                     a[(i - 1) * (x + 1) + j * x]));
  printf("%lld\n", dp[lg][sg]);
  return 0;
}
