#include <bits/stdc++.h>
using namespace std;
const int INF = (int)2e9 + 10;
const int mod = (int)1e9 + 7;
const int N = (int)1e6 + 10;
const long long LLINF = (long long)1e18 + 10;
const long double pi = acos(-1.0);
template <typename T1, typename T2>
bool umin(T1 &x, const T2 &y) {
  if (x > y) return x = y, true;
  return false;
}
template <typename T1, typename T2>
bool umax(T1 &x, const T2 &y) {
  if (x < y) return x = y, true;
  return false;
}
template <typename T>
T getint() {
  char c = getchar();
  T p = 1, x = 0;
  while (c == ' ' || c == '\n') c = getchar();
  if (c == '-') p = -1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * p;
}
int t[N];
int n, k;
vector<int> a;
void add(int r, int val) {
  for (; r <= n; r |= r + 1) {
    t[r] += val;
  }
}
int get(int r) {
  int res = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) res += t[r];
  return res;
}
int get(int l, int r) {
  int sum = get(r) - get(l - 1);
  return bool(sum == r - l + 1);
}
bool check(int x) {
  for (int i = 0; i <= n; ++i) t[i] = 0;
  for (int i = n - 1; i >= 0; --i) {
    int j = upper_bound((a).begin(), (a).end(), a[i] + x) - a.begin();
    if (i + k > j) {
      add(i, 1);
      continue;
    }
    int mn = get(i + k, j);
    add(i, mn);
  }
  return (get(0, 0) == 0);
}
int main() {
  srand(time(NULL));
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort((a).begin(), (a).end());
  int l = -1, r = INF;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  cout << r;
}
