#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>> &pq) {return (ll)pq.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>, greater<T>> &pq) {return (ll)pq.size(); }
ll sz(string &s) {return (ll)s.size(); } 
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

#define SEG_LEN (1 << 21)

ll seg[SEG_LEN*2];

void update(ll ind,ll v){
    ind += SEG_LEN;
    seg[ind] = v;
    while(1){
        ind /= 2;
        if(ind <= 0) break;
        seg[ind] = max(seg[ind*2],seg[ind*2+1]);
    }
    return;
}

ll find(ll l, ll r){
    l += SEG_LEN; r += SEG_LEN;
    ll res = 0;
    while(l < r){
        if(l % 2 == 1){
            res = max(res,seg[l]);
            l++;
        }
        l /= 2;
        
        if(r % 2 == 1){
            res = max(res,seg[r-1]);
            r--;
        }
        r /= 2;
    }
    return res;
}

int main(){
    ll n,k;
    cin >> n >> k;

    ll a[n];
    rep(i,0,n){
        cin >> a[i];
    }

    rep(k,0,n){
        ll i = n-k-1;
        update(a[i],find(max(1LL,a[i]-k),a[i]+k+1)+1LL);
    }

    cout << find(1,SEG_LEN) << endl;


    return 0;
}

