#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+14;
int n, a[maxn], f[maxn], p;
map < int , int > m;
bool comp(int a, int b) {
return a >= b;
}
void solve(){
cin >> n >> p;
for (int i = 1; i <= n; i++){
cin >> a[i];
}
f[n + 1] = -1e9 + 31;
for (int i = n; i >= 1; i--){
f[i] = max(f[i + 1], a[i]);
}
int ans = 0;
for (int i = 1; i <= n; i++) {
int pos = lower_bound(f + i, f + 1 + n, a[i] + p, comp) - f - 1;
ans = max(ans , pos - i);
}
cout << ans ;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen("input.txt","r")){
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
}
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBtYXhuPTFlNisxNDsKaW50IG4sIGFbbWF4bl0sIGZbbWF4bl0sIHA7Cm1hcCA8IGludCAsIGludCA+IG07CmJvb2wgY29tcChpbnQgYSwgaW50IGIpIHsKCXJldHVybiBhID49IGI7Cn0Kdm9pZCBzb2x2ZSgpewoJY2luID4+IG4gPj4gcDsKCWZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkrKyl7CgkJY2luID4+IGFbaV07Cgl9CglmW24gKyAxXSA9IC0xZTkgKyAzMTsKCWZvciAoaW50IGkgPSBuOyBpID49IDE7IGktLSl7CgkJZltpXSA9IG1heChmW2kgKyAxXSwgYVtpXSk7Cgl9CgkKCWludCBhbnMgPSAwOwoJZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKSB7CgkJaW50IHBvcyA9IGxvd2VyX2JvdW5kKGYgKyBpLCBmICsgMSArIG4sIGFbaV0gKyBwLCBjb21wKSAtIGYgLSAxOyAKCQlhbnMgPSBtYXgoYW5zICwgcG9zIC0gaSk7Cgl9CgkKCWNvdXQgPDwgYW5zIDsKfQppbnQgbWFpbigpewoJaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsKCWNpbi50aWUoMCk7ICAgIGNvdXQudGllKDApOwoJaWYgKGZvcGVuKCJpbnB1dC50eHQiLCJyIikpewoJCWZyZW9wZW4oImlucHV0LnR4dCIsInIiLHN0ZGluKTsKCQlmcmVvcGVuKCJvdXRwdXQudHh0IiwidyIsc3Rkb3V0KTsKCX0KCXNvbHZlKCk7CglyZXR1cm4gMDsKfQo=