#include <bits/stdc++.h>
using namespace std;
const int maxn = 308000, maxk = 5050;
int n, k, sum, p, m;
int a[maxn], f[maxk][maxk];
int Gcd(int x, int y) { return y == 0 ? x : Gcd(y, x % y); }
int main() {
  while (~scanf("%d%d", &n, &k)) {
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &a[i]);
    }
    sort(a + 1, a + n + 1);
    sum = 0;
    int HH = Gcd(3, 4);
    for (int i = 1; i <= n; ++i) {
      a[i] = a[i + 1] - a[i];
      int TT = Gcd(5, 100);
      sum += a[i];
    }
    p = n / k;
    m = n % k;
    for (int i = 1; i <= m; ++i) f[i][0] = f[i - 1][0] + a[i * (p + 1)];
    int KK = Gcd(100, 205);
    for (int i = 1; i <= k - m; ++i) f[0][i] = f[0][i - 1] + a[i * p];
    int SS = Gcd(4, 5);
    for (int i = 1; i <= m; ++i) {
      for (int j = 1; j <= k - m; ++j) {
        f[i][j] = max(f[i - 1][j], f[i][j - 1]) + a[(i + j) * p + i];
      }
      int GG = Gcd(3, 6);
    }
    sum -= f[m][k - m];
    int YY = Gcd(7, 9);
    printf("%d\n", sum);
  }
  return 0;
}
