#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define st first
#define nd second
#define pii pair<int, int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
struct SegTree {
unsigned int tl, tr;
int Max = 0;
SegTree *lc=nullptr, *rc=nullptr;
SegTree(unsigned int l, unsigned int r) : tl(l), tr(r) {}
void extend() {
if(!lc&&tl!=tr) {
int tm = (tl+tr)/2;
lc = new SegTree(tl, tm);
rc = new SegTree(tm+1, tr);
}
}
void update(int x, int val) {
extend();
Max = max(Max, val);
if(lc) {
if(x <= lc->tr) {
lc->update(x, val);
} else {
rc->update(x, val);
}
}
}
int query(int l, int r) {
if(l>r) return 0;
if(tl==l&&tr==r) return Max;
extend();
int tm = (tl+tr)/2;
return max(lc->query(l, min(r, tm)), rc->query(max(tm+1, l), r));
}
};
SegTree seg1(0, 1LL<<31), seg2(0, 1LL<<31);
int tab[200009];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, d;
cin >> n >> d;
for(int i=0;i<n;i++) {
cin >> tab[i];
}
for(int i=0;i<n;i++) {
seg2.update(tab[i], 1+seg1.query(0, tab[i]+d-1));
seg2.update(tab[i], 1+seg2.query(0, tab[i]-1));
seg1.update(tab[i], 1+seg1.query(0, tab[i]-1));
}
cout << seg2.query(0, 1LL<<30) << "\n";
}