#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long v[300005];
bool solve(long long val) {
  bool dp[300005];
  memset(dp, 0, sizeof dp);
  int start = 0;
  if (v[k - 1] - v[0] <= val) dp[k - 1] = 1;
  for (int i = k; i < n; i++) {
    while (v[i] - v[start] > val) start++;
    if (start > 0) {
      while (!dp[start - 1] && start < i) start++;
    }
    if (start <= i - k + 1)
      dp[i] = 1;
    else
      dp[i] = 0;
  }
  return dp[n - 1];
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> v[i];
  sort(v, v + n);
  long long high = v[n - 1] - v[0];
  long long low = v[n - 1] - v[n - k] - 1;
  while (high - low > 1) {
    long long mid = (low + high) / 2;
    if (solve(mid))
      high = mid;
    else
      low = mid;
  }
  cout << high << endl;
  return 0;
}
