#include <bits/stdc++.h>
using namespace std;
int N, K;
int A[714514];
long long dp[5100][5100];
int main() {
  scanf("%d%d", &N, &K);
  for (int(i) = 0; (i) < (N); (i)++) scanf("%d", &A[i]);
  sort(A, A + N);
  int p1 = N % K;
  int p2 = K - p1;
  int w = N / K;
  for (int(i) = 0; (i) < (5100); (i)++)
    for (int(j) = 0; (j) < (5100); (j)++) dp[i][j] = 1LL << 61;
  dp[0][0] = 0;
  for (int(i) = 0; (i) < (p1 + 1); (i)++)
    for (int(j) = 0; (j) < (p2 + 1); (j)++) {
      int cc = i * (w + 1) + j * w;
      if (cc > N) continue;
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + abs(A[cc] - A[cc + w]));
      dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + abs(A[cc] - A[cc + w - 1]));
    }
  printf("%d\n", dp[p1][p2]);
}
