#include <bits/stdc++.h>
using namespace std;
int n, k;
int d[300300];
int sum[300300];
int a[300300];
inline bool can(int x) {
  d[0] = 1;
  sum[0] = 1;
  for (int i = 1; i < k; ++i) {
    d[i] = 0;
    sum[i] = sum[i - 1];
  }
  d[k] = 1;
  sum[k] = sum[k - 1] + 1;
  for (int i = k + 1; i <= n; ++i) {
    int l = 1, r = (i - k + 1), j = -1;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (a[i] - a[mid] <= x)
        j = mid, r = mid - 1;
      else
        l = mid + 1;
    }
    if (j == -1) {
      d[i] = 0;
      sum[i] = sum[i - 1];
      continue;
    }
    if (sum[i - k] - sum[j - 2] > 0) {
      d[i] = 1;
    } else {
      d[i] = 0;
    }
    sum[i] = sum[i - 1] + d[i];
  }
  return d[n] > 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  sort(a + 1, a + n + 1);
  int l = a[k] - a[1], r = a[n] - a[1];
  int ans = r;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (can(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
