#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
inline int read() {
  int a = 0, c;
  do c = getchar();
  while (!isdigit(c));
  while (isdigit(c)) {
    a = a * 10 + c - '0';
    c = getchar();
  }
  return a;
}
int n, k;
int v[MAXN];
int que[MAXN];
int dp[MAXN];
inline bool check(int mid) {
  memset(dp, 0, sizeof dp);
  dp[0] = 1;
  int l = 1, r = 0;
  for (int i = k; i <= n; i++) {
    if (dp[i - k]) que[++r] = i - k;
    while (l <= r && v[i] - v[que[l] + 1] > mid) l++;
    if (l <= r) dp[i] = 1;
  }
  return dp[n];
}
int main() {
  n = read(), k = read();
  for (int i = 1; i <= n; i++) {
    v[i] = read();
  }
  sort(v + 1, v + n + 1);
  int L = 0, R = 1e9, mid;
  while (L <= R) {
    mid = (L + R) >> 1;
    if (check(mid))
      R = mid - 1;
    else
      L = mid + 1;
  }
  printf("%d\n", R + 1);
  return 0;
}
