#include <bits/stdc++.h>
using namespace std;
int a[1111111], n, k, f[1111111], sum[1111111];
bool ck(int value) {
  int mm = a[1];
  for (int i = 0; i <= n; i++) f[i] = sum[i] = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] - mm <= value && i >= k) {
      f[i] = 1;
      sum[i] = sum[i - 1] + f[i];
    }
  }
  int l = 1;
  for (int i = k + 1; i <= n; i++) {
    while (a[i] - a[l] > value) l++;
    if (l - 1 <= i - k) {
      if (l == 1 || sum[i - k] - sum[l - 2] > 0)
        f[i] = 1;
      else
        f[i] = 0;
    } else {
      f[i] = 0;
    }
    sum[i] = sum[i - 1] + f[i];
  }
  return (f[n] == 1);
}
int main(void) {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  int l = 0;
  int r = 2111111111;
  for (int iter = 0; iter < 40; iter++) {
    int m = (l + r) / 2;
    if (ck(m) == true)
      r = m;
    else
      l = m + 1;
  }
  cout << l << endl;
  return 0;
}
