#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvl = vector<vll>;
using pll = pair<ll,ll>;
using vpl = vector<pll>;
using vvp = vector<vpl>;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(),v.end()
int main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);
ll n, x;
cin >> n >> x;
vll ar(n);
for(ll& i:ar)cin >> i;
vll lo(n);
ll mx = 0;
vll bes(n+1, 2e9);
bes[0]=-2e9-1;
for(ll i = n-1; i >= 0; --i){
lo[i]=lower_bound(all(bes), -ar[i]+x)-bes.begin();
ll it = lower_bound(all(bes), -ar[i])-bes.begin();
bes[it]=-ar[i];
}
bes = vll(n+1, 2e9);
bes[0]=-2e9-1;
ll ans = 0;
for(ll i = 0; i < n; ++i){
ll it = lower_bound(all(bes), ar[i])-bes.begin();
bes[it]=ar[i];
ans = max(ans, it+lo[i]-1);
}
cout << ans;
}