#include<atcoder/all>
using namespace atcoder;

#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int op(int a, int b){return max(a, b);}
int e(){return -1;}

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }
    segtree<int,op,e> seg(300010);
    seg.set(a[0], 1);
    REP(i, n-1){
        int now = seg.prod(max(a[i]-k, 0), min(a[i]+k+1, 300000));
        seg.set(a[i], now+1);
    }
    cout << seg.all_prod() << endl;
}
