#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10;
int n, k;
int v[MAXN];
int f[MAXN];
int search(int num) {
  int l = 1, r = n;
  while (l < r) {
    int mid = (l + r) / 2;
    if (v[mid] < num) {
      l = mid + 1;
    } else {
      r = mid;
    }
  }
  return l;
}
bool check(int len) {
  memset(f, 0, sizeof(f));
  for (int i = 1; i <= n; i++) {
    int t = search(v[i] - len);
    if (t == 1 && i - t + 1 >= k) {
      if (i == n) {
        return true;
      }
      f[i] += f[i - 1] + 1;
    } else if (t >= 2 && i - t + 1 >= k && f[i - k] - f[t - 2] > 0) {
      if (i == n) {
        return true;
      }
      f[i] += f[i - 1] + 1;
    } else {
      f[i] = f[i - 1];
    }
  }
  return false;
}
int main(int argc, const char* argv[]) {
  scanf("%d", &(n));
  scanf("%d", &(k));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &(v[i]));
  }
  sort(v + 1, v + 1 + n);
  int l = 0, r = 1000000000;
  while (l < r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  printf("%d\n", l);
  return 0;
}
