#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 3e5 + 5;
int n, k;
long long x, dp[5005][5005], a[MAXN];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  a[0] = a[1];
  a[n + 1] = a[n];
  int len1 = n / k;
  int len2 = n / k + 1;
  int cnt1 = k - n % k;
  int cnt2 = n % k;
  for (int i = 0; i <= cnt1; i++) {
    for (int j = 0; j <= cnt2; j++) {
      int pos1 = (i - 1) * len1 + j * len2;
      if (i)
        dp[i][j] = (dp[i][j]) > (dp[i - 1][j] + a[pos1 + 1] - a[pos1])
                       ? (dp[i][j])
                       : (dp[i - 1][j] + a[pos1 + 1] - a[pos1]);
      int pos2 = i * len1 + (j - 1) * len2;
      if (j)
        dp[i][j] = (dp[i][j]) > (dp[i][j - 1] + a[pos2 + 1] - a[pos2])
                       ? (dp[i][j])
                       : (dp[i][j - 1] + a[pos2 + 1] - a[pos2]);
    }
  }
  cout << a[n] - a[1] - dp[cnt1][cnt2] << endl;
  return 0;
}
