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