#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[500005];
set<int> second;
inline bool can(int X) {
  second.clear();
  second.insert(-1);
  for (int i = 0, j = 0; i < n; ++i) {
    while (j < i && a[i] - a[j] > X) ++j;
    int kk = i - k + 1;
    if (j > kk) continue;
    auto it = second.lower_bound(j - 1);
    if (it != second.end() && *it < kk) {
      second.insert(i);
    }
  }
  return (int(second.size())) >= 1 && *(--second.end()) == n - 1;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  sort(a, a + n);
  int l = -1, r = int(1e9) + 1;
  while (l + 1 < r) {
    int m = (l + r) / 2;
    if (!can(m))
      l = m;
    else
      r = m;
  }
  printf("%d\n", r);
  return 0;
}
