#include <bits/stdc++.h>
using namespace std;
int a[300010];
int n, k, m;
int sum[300010];
bool check(int delta) {
  sum[0] = 0;
  for (int i = 1; i <= n; i++) {
    int pos1 = lower_bound(a + 1, a + i, a[i] - delta) - a;
    int pos2 = i - k + 1;
    int flag = 1;
    if (pos1 > pos2)
      flag = 0;
    else {
      int cnt = sum[pos2 - 1] - sum[pos1 - 2];
      if (cnt <= 0 && pos1 != 1) flag = 0;
    }
    sum[i] = sum[i - 1] + flag;
    if (i == n) return (flag);
  }
  return false;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  if (k == 1) {
    puts("0");
    return 0;
  }
  int l = -1, r = 1e9 + 100, mid;
  while (l + 1 < r)
    if (check(mid = l + (r - l) / 2))
      r = mid;
    else
      l = mid;
  cout << r << endl;
  return 0;
}
