#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int& i : v) cin >> i;
  sort(v.begin(), v.end());
  long long l = 0, r = 1e10;
  while (l < r) {
    long long m = (l + r) / 2;
    vector<int> ok(n, 0);
    int dentro = 0, j = 0;
    for (int i = 0; i < n; i++) {
      while (j + 1 <= i - k + 1 and v[i] - v[j + 1] > m) {
        dentro -= ok[j];
        j++;
      }
      if (i - k >= 0) dentro += ok[i - k];
      ok[i] = (i + 1 >= k and v[i] - v[0] <= m) or !!dentro;
    }
    if (ok[n - 1])
      r = m;
    else
      l = m + 1;
  }
  cout << l << '\n';
  exit(0);
}
