#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const int maxm = 256 + 10;
const int inf = 2e9 + 7;
const int mod = 1e9 + 7;
const double eps = 1e-9;
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, k;
int dp[maxn], a[maxn];
bool check(int x) {
  int last = 0;
  for (int i = 1; i <= n; ++i) dp[i] = 0;
  for (int i = k; i <= n; ++i) {
    if (a[i] - a[dp[i - k] + 1] <= x) last = i;
    dp[i] = last;
  }
  return dp[n] == n;
}
int main() {
  n = read();
  k = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  if (k == 1) {
    puts("0");
    return 0;
  }
  sort(a + 1, a + n + 1);
  int l = a[k] - a[1], r = a[n] - a[1];
  while (l < r) {
    int mid = l + r >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", r);
}
