#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
  cin >> n >> k;
  vector<int> a;
  a.resize(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  if (n % k == 0) {
    int result = 0;
    for (int i = 1; i < n; i++) {
      if (i % (n / k) != 0) result += a[i] - a[i - 1];
    }
    cout << result;
  } else {
    int y2 = n % k;
    int y3 = k - y2;
    vector<vector<int> > b;
    b.resize(y2 + 1);
    for (int i = 0; i < y2 + 1; ++i) b[i].resize(y3 + 1);
    for (int i = 0; i < y2 + 1; i++) {
      for (int j = 0; j < y3 + 1; j++) {
        if ((i < y2 || j < y3) && (i > 0 || j > 0)) {
          b[i][j] = a[i * (n / k + 1) + j * (n / k)] -
                    a[i * (n / k + 1) + j * (n / k) - 1];
          int max = 0;
          if (i > 0) max = b[i - 1][j];
          if (j > 0 && b[i][j - 1] > max) max = b[i][j - 1];
          b[i][j] += max;
        }
      }
    }
    int result = 0;
    for (int i = 1; i < n; i++) {
      result += a[i] - a[i - 1];
    }
    int temp = b[y2 - 1][y3];
    if (b[y2][y3 - 1] > temp) {
      temp = b[y2][y3 - 1];
    }
    result -= temp;
    cout << result;
  }
}
