#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
int const inf = 1000000000;
inline int get(const vector<int>& tree, int l, int r) {
  int sz = tree.size() >> 1;
  int res = inf;
  for (l += sz, r += sz; l <= r; l >>= 1, r >>= 1) {
    if (l & 1) res = min(res, tree[l++]);
    if (~r & 1) res = min(res, tree[r--]);
  }
  return res;
}
inline void upd(vector<int>& tree, int ind, int val) {
  int sz = tree.size() >> 1;
  for (tree[ind += sz] = val; ind > 1; ind >>= 1)
    tree[ind >> 1] = min(tree[ind], tree[ind ^ 1]);
}
bool check(vector<int> a, int k, int val) {
  int n = a.size();
  vector<int> d(n + 1, inf);
  int sz = 1;
  while (sz <= n) sz <<= 1;
  vector<int> tree(2 * sz, inf);
  upd(tree, 0, 0);
  int l = 0;
  for (int i = 0; i < n; ++i) {
    while (a[i] - a[l] > val) ++l;
    if (i - k >= l - 1) upd(tree, i + 1, get(tree, l, i - k + 1));
  }
  return tree[sz + n] <= (n + k - 1) / k;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int& x : a) cin >> x;
  sort(begin(a), end(a));
  int l = -1;
  int r = 1000000000;
  while (r - l > 1) {
    int mid = (l + r) >> 1;
    (check(a, k, mid) ? r : l) = mid;
  }
  cout << r << endl;
}
