#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[300005];
long long dp[5005][5005];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int i, j;
  int large = n % k;
  int small = k - n % k;
  int len = n / k;
  for (i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  sort(a + 1, a + n + 1);
  for (i = 0; i <= large + 1; i++) {
    for (j = 0; j <= small + 1; j++) {
      dp[i][j] = 1e15;
    }
  }
  dp[0][0] = 0;
  for (i = 0; i <= large; i++) {
    for (j = 0; j <= small; j++) {
      int cur = i * (len + 1) + j * (len) + 1;
      if (i < large) {
        int x = a[cur + len] - a[cur];
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + x);
      }
      if (j < small) {
        int x = a[cur + len - 1] - a[cur];
        dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + x);
      }
    }
  }
  cout << dp[large][small];
}
