#include <bits/stdc++.h>
using namespace std;
int N, K;
vector<int> arr;
int is_can(int mid) {
  vector<int> dp(N + 1, 0);
  int l = 1, cnt = 0;
  for (int i = K; i <= N; i++) {
    int r = i - K + 1;
    cnt += dp[r - 1];
    while (l <= r && arr[i] - arr[l] > mid) {
      cnt -= dp[l - 1];
      l++;
    }
    if (l == 1 || cnt) dp[i] = 1;
  }
  return dp[N];
}
int main() {
  scanf("%d%d", &N, &K);
  arr.resize(N + 1);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &arr[i]);
  }
  sort(arr.begin() + 1, arr.end());
  int s = 0, e = arr[N] - arr[1], x = arr[N] - arr[1];
  while (s <= e) {
    int mid = (s + e) / 2;
    if (is_can(mid)) {
      x = mid;
      e = mid - 1;
    } else {
      s = mid + 1;
    }
  }
  printf("%d", x);
  return 0;
}
