#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 77;
long long a[N], f[N], l, r;
int n, k;
bool check(int mid) {
  for (int i = 1; i <= n; i++) f[i] = 0;
  f[0] = 1;
  int pl = 1, pr;
  for (int i = 1; i <= n; i++) {
    while (a[i] - a[pl] > mid) pl++;
    pr = i - k + 1;
    for (int j = pl; j <= pr; j++) {
      if (f[j - 1]) {
        f[i] = 1;
        break;
      } else
        pl++;
    }
  }
  return f[n];
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    r = max(a[i], r);
  }
  for (int i = 1; i <= n; i++) f[i] = 0x3f3f3f3f;
  sort(a + 1, a + 1 + n);
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%lld", l);
  return 0;
}
