#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e5 + 5;
int n, k;
int arr[MAX], pref[MAX], good[MAX];
bool ok(int limit) {
  memset(good, 0, sizeof good);
  memset(pref, 0, sizeof pref);
  good[0] = pref[0] = 1;
  for (int i = int(1); i < int(n + 1); ++i) {
    int left = 1, right = i;
    int f = -1;
    while (left <= right) {
      int mid = (left + right) / 2;
      if (arr[i] - arr[mid] <= limit) {
        f = mid;
        right = mid - 1;
      } else {
        left = mid + 1;
      }
    }
    if (f <= i - k + 1) {
      int has = pref[i - k] - (f - 1 == 0 ? 0 : pref[f - 2]);
      good[i] = has != 0;
    }
    pref[i] = pref[i - 1] + good[i];
  }
  return good[n];
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = int(1); i < int(n + 1); ++i) {
    scanf("%d", arr + i);
  }
  sort(arr + 1, arr + n + 1);
  int left = 0, right = (int)1e9;
  int ans = -1;
  while (left <= right) {
    int mid = (left + right) / 2;
    if (ok(mid)) {
      ans = mid;
      right = mid - 1;
    } else {
      left = mid + 1;
    }
  }
  printf("%d\n", ans);
  return 0;
}
