#include <bits/stdc++.h>
using namespace std;
inline void in(int &n) {
  n = 0;
  int ch = getchar();
  int sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') sign = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    n = (n << 3) + (n << 1) + ch - '0', ch = getchar();
  }
  n = n * sign;
}
int a[300005];
long long int A[300005], B[300005], memo[5005][5005];
int X, Y;
long long int func(int x, int y, int p, int q, int n) {
  if (x == 0 && y == 0) {
    return 0;
  }
  if (x < 0 || y < 0) {
    return ((long long int)(1e18));
  }
  int pos = (X - x) * p + (Y - y) * q + 1;
  if (pos > n) {
    return ((long long int)(1e18));
  }
  if (memo[x][y] != -1) {
    return memo[x][y];
  }
  long long int ans;
  ans = min(A[pos] + func(x - 1, y, p, q, n), B[pos] + func(x, y - 1, p, q, n));
  memo[x][y] = ans;
  return ans;
}
int main() {
  int n, k;
  in(n);
  in(k);
  for (int i = 1; i <= n; i++) {
    in(a[i]);
  }
  sort(a + 1, a + 1 + n);
  int p, q;
  X = n % k;
  p = (n / k + 1);
  Y = k - X;
  q = n / k;
  for (int i = 1; i <= n; i++) {
    if (i + p - 1 <= n) {
      A[i] = a[i + p - 1] - a[i];
    } else {
      A[i] = ((long long int)(1e18));
    }
    if (i + q - 1 <= n) {
      B[i] = a[i + q - 1] - a[i];
    } else {
      B[i] = ((long long int)(1e18));
    }
  }
  memset(memo, -1, sizeof(memo));
  long long int ans = func(X, Y, p, q, n);
  printf("%I64d\n", ans);
  return 0;
}
