#include <bits/stdc++.h>
using namespace std;
bool check(int n, int k, int diff, int a[]) {
  vector<bool> dp(n);
  int last = -1;
  for (int i = k - 1; i < n; i++) {
    int low = 0, high = i - k + 1;
    while (low < high) {
      int pivot = (low + high) / 2;
      if (a[i] - a[pivot] > diff)
        low = pivot + 1;
      else
        high = pivot;
    }
    if (a[i] - a[low] > diff) {
      continue;
    }
    if (low == 0)
      dp[i] = 1;
    else if (dp[low - 1] || last > low - 1)
      dp[i] = 1;
    if (dp[i - k + 1]) last = i - k + 1;
  }
  return dp[n - 1];
}
int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int low = 0, high = a[n - 1] - a[0];
  while (low < high) {
    int pivot = (low + high) / 2;
    if (check(n, k, pivot, a))
      high = pivot;
    else
      low = pivot + 1;
  }
  cout << low << endl;
  return 0;
}
