#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10;
int n, k;
int v[MAXN];
int used[MAXN];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%d", &v[i]);
  sort(v, v + n);
  int l = 0, r = 1000000000;
  while (l != r) {
    int mid = (l + r) / 2;
    int left_p = 0, right_p = 0, cur_p = 0;
    bool fl = false;
    queue<pair<int, int>> q;
    q.push(make_pair(0, 0));
    while (!q.empty()) {
      int L = q.front().first;
      int R = q.front().second;
      if (R == n) {
        r = mid;
        fl = true;
        break;
      }
      q.pop();
      if (cur_p < L) cur_p = L;
      for (int i = cur_p; i <= R; i++) {
        cur_p = i + 1;
        if (i + k > left_p) left_p = i + k;
        while (right_p < n && v[right_p] - v[i] <= mid) right_p++;
        if (left_p <= right_p) q.push(make_pair(left_p, right_p));
      }
    }
    if (!fl) l = mid + 1;
  }
  cout << l;
}
