#include <bits/stdc++.h>
using namespace std;
const int M = 3e5 + 10;
int a[M], dp[5010][5010];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + n + 1);
  a[0] = a[1], a[n + 1] = a[n];
  int len1 = n / k + 1, len2 = n / k;
  int count1 = n % k, count2 = k - count1;
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i <= count1; i++) {
    for (int j = 0; j <= count2; j++) {
      if (i) {
        int pos = (i - 1) * len1 + j * len2;
        dp[i][j] = max(dp[i][j], dp[i - 1][j] + a[pos + 1] - a[pos]);
      }
      if (j) {
        int pos = i * len1 + (j - 1) * len2;
        dp[i][j] = max(dp[i][j], dp[i][j - 1] + a[pos + 1] - a[pos]);
      }
    }
  }
  int ans = a[n] - a[1] - dp[count1][count2];
  printf("%d\n", ans);
  return 0;
}
