#include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
  T sum = 0, sign = 1;
  char c = getchar();
  while (!((c) >= '0' && (c) <= '9')) {
    if (c == '-') sign = -1;
    c = getchar();
  }
  while (((c) >= '0' && (c) <= '9')) {
    sum = (sum << 1) + (sum << 3) + c - '0';
    c = getchar();
  }
  x = sum * sign;
}
template <typename T>
inline T max(T a, T b) {
  return a > b ? a : b;
}
template <typename T>
inline T min(T a, T b) {
  return a < b ? a : b;
}
template <typename T>
inline void write(T a) {
  if (a < 0) putchar('-'), a = -a;
  if (a / 10) write(a / 10);
  putchar(a % 10 + '0');
}
const int N = 3e5 + 50;
int n, k;
int val[N];
int f[N];
inline bool judge(int limit) {
  memset(f, 0, sizeof(f));
  f[0] = 1;
  int l = 1, r = 0;
  for (int i = 1; i <= n; ++i) {
    while (val[i] - val[l] > limit) ++l;
    r = i - k + 1;
    for (int j = l; j <= r; ++j)
      if (f[j - 1]) {
        f[i] = 1;
        break;
      } else
        ++l;
  }
  return f[n];
}
int main() {
  read(n), read(k);
  int l = 0, r = 0;
  for (int i = 1; i <= n; ++i) read(val[i]), r = max(r, val[i]);
  std::sort(val + 1, val + 1 + n);
  while (l < r) {
    int mid = l + r >> 1;
    if (judge(mid))
      r = mid;
    else
      l = mid + 1;
  }
  write(l), puts("");
  return 0;
}
