#include<iostream>
#include<vector>
#include<functional>
#include<atcoder/all>
using namespace std;
typedef long long li;
#define minimize(a,b) (a>(b)?a=(b),1:0)
#define maximize(a,b) (a<(b)?a=(b),1:0)
#define N_MAX 300010
#define M_MAX 1000000001
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

struct mono{
  li ma;
  mono(li a=0){ma=a;};
};

mono e(){
  return mono();
}

mono op(mono m,mono n){
  return {max(m.ma,n.ma)};
}
// pair 型
std::ostream& operator<<(std::ostream& os, const mono& p){
  cout << p.ma ;
  return os;
}


int main(){
  int n,k; cin >>n >>k;
  atcoder::segtree<mono,op,e> sgt(k+N_MAX);
  rep(i,n){
    li x; cin >>x;
    li a=x-k,b=x+k+1;
    maximize(a,0); minimize(b,k+N_MAX);
    li m=sgt.prod(a,b).ma;
    if(df)print(a,b,m);
    sgt.set(x,m+1);
  }
  print(sgt.prod(0,N_MAX));
}
