#include <bits/stdc++.h>
using namespace std;
long long dp[5010][5010];
int n, k, a, b, x, y, z[300010];
long long inf = 1e18;
int main() {
  while (scanf("%d %d", &n, &k) != EOF) {
    for (int i = 1; i <= n; i++) scanf("%d", &z[i]);
    sort(z + 1, z + n + 1);
    x = n / k;
    y = n / k + 1;
    b = n - k * x;
    a = k - b;
    dp[1][0] = z[y] - z[1];
    dp[1][1] = z[x] - z[1];
    for (int i = 2; i <= a + b; i++) {
      for (int j = 0; j <= min(a, i); j++) {
        if (i == j) {
          dp[i][j] = dp[i - 1][j - 1] + (long long)z[(i - 1) * x + x] -
                     z[(i - 1) * x + 1];
        } else {
          int tmp = j * x + (i - 1 - j) * y;
          if (tmp + y <= n)
            dp[i][j] = dp[i - 1][j] + (long long)z[tmp + y] - z[tmp + 1];
          else
            dp[i][j] = inf;
          if (j > 0) {
            tmp = (j - 1) * x + (i - j) * y;
            if (tmp + x <= n)
              dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] +
                                           (long long)z[tmp + x] - z[tmp + 1]);
          }
        }
      }
    }
    printf("%I64d\n", dp[a + b][a]);
  }
  return 0;
}
