#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int maxn = 3e5 + 10;
int n, k;
int a[maxn];
int cover[maxn << 2];
void pushup(int rt) { cover[rt] = max(cover[rt << 1], cover[rt << 1 | 1]); }
void update(int rt, int l, int r, int pos) {
  if (l == r) {
    cover[rt] = l;
    return;
  }
  if (pos <= (l + r) / 2)
    update(rt << 1, l, (l + r) / 2, pos);
  else
    update(rt << 1 | 1, (l + r) / 2 + 1, r, pos);
  pushup(rt);
}
int query(int rt, int l, int r, int qstart, int qend) {
  if (qstart <= l && r <= qend) return cover[rt];
  int ans = 0;
  if (qstart <= (l + r) / 2) ans = query(rt << 1, l, (l + r) / 2, qstart, qend);
  if (qend > (l + r) / 2)
    ans = max(ans, query(rt << 1 | 1, (l + r) / 2 + 1, r, qstart, qend));
  return ans;
}
int check(int x) {
  memset(cover, 0, sizeof(cover));
  update(1, 1, n + 10, 1);
  for (int i = k; i <= n; i++) {
    int ans = query(1, 1, n + 10, 1, i - k + 1);
    if (ans && a[i] - a[ans] <= x) update(1, 1, n + 10, i + 1);
  }
  return query(1, 1, n + 10, n + 1, n + 1) != 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  int l = 0, r = 1e9 + 10;
  while (1) {
    if (l + 1 >= r) {
      if (check(l))
        cout << l;
      else
        cout << r;
      return 0;
    }
    if (check((l + r) / 2))
      r = (l + r) / 2;
    else
      l = (l + r) / 2 + 1;
  }
  return 0;
}
