#include <bits/stdc++.h>
using namespace std;
int N, K;
int A[300005];
int DP[300005];
bool chk(int d) {
  int mxp = 0;
  for (int i = K; i <= N; i++) {
    if (A[i] - A[DP[i - K] + 1] <= d) mxp = i;
    DP[i] = mxp;
  }
  return mxp == N;
}
int main() {
  cin >> N >> K;
  for (int i = 1; i <= N; i++) cin >> A[i];
  sort(A + 1, A + 1 + N);
  int l = -1, r = 1e9;
  while (l + 1 < r) {
    int md = (l + r) / 2;
    if (chk(md))
      r = md;
    else
      l = md;
  }
  cout << r << '\n';
}
