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

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

int e(){return 0;}

int main(){
  int N,K;cin>>N>>K;
  segtree<int,mx,e> S(300001);
  for(int i=0;i<N;i++){
    int a;cin>>a;
    S.set(a,S.prod(max(a-K,0),min(a+K+1,300001))+1)//ふーん
  }
  
  cout<<S.prod(0,300001)<<endl;
}
  