//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

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

int e(){
    return 0;
}

int main(){
ios::sync_with_stdio(false);cin.tie(nullptr);
cout << fixed << setprecision(10);
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
        rep(i,n) cin>>a.at(i);
    rep(i,n) a[i] --;
    int max_k=300000;
    segtree<int,op,e> sg(max_k);
    int ans=0;
    int x;
    rep(i,n){
      
        x=sg.prod(max(0,a[i]-k),min(max_k,a[i]+k+1));
        sg.set(a[i],x+1);
        ans=max(ans,x+1);
    }
    cout<<ans<<endl;
}/*
./problem.exe
*/