#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int n, k;
long long ori[maxn];
long long dp[5005][5005];
long long ans;
int main() {
  while (~scanf("%d%d", &n, &k)) {
    ans = 0;
    for (int i = 1; i <= n; i++) scanf("%I64d", ori + i);
    sort(ori + 1, ori + 1 + n);
    memset(dp, 0x3f, sizeof(dp));
    dp[0][0] = 0;
    int large = n / k + 1;
    int small = n / k;
    int cntl = n % k;
    int cnts = k - n % k;
    int qian, hou;
    for (int i = 0; i <= cntl; i++) {
      for (int j = 0; j <= cnts; j++) {
        if (i > 0) {
          qian = (i - 1) * large + j * small + 1;
          hou = (i)*large + j * small;
          dp[i][j] = min(dp[i][j], dp[i - 1][j] + ori[hou] - ori[qian]);
        }
        if (j > 0) {
          qian = i * large + (j - 1) * small + 1;
          hou = i * large + j * small;
          dp[i][j] = min(dp[i][j], dp[i][j - 1] + ori[hou] - ori[qian]);
        }
      }
    }
    cout << dp[cntl][cnts] << "\n";
  }
}
