#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 5;
long long n, k, a[N], num[N], sumn[N];
set<long long> s;
int main() {
  cin >> n >> k;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    num[a[i]]++;
  }
  for (long long i = 0; i < n; i++) {
    sumn[i] = sumn[i - 1] + num[i];
  }
  long long x;
  long long mx = 0;
  for (long long i = 0;;) {
    x = upper_bound(a, a + n, a[i] + k) - a;
    if (x == n) break;
    mx = max(mx, sumn[a[x]] - sumn[a[i]]);
    i += x;
  }
  cout << mx;
}
