#include<bits/stdc++.h>
#include<atcoder/all>
#define int long long
using namespace std;
using namespace atcoder;
int mx(int a,int b){
  return max(a,b);
}
int e(){
  return 0;
}
signed main(){
  int N,K;
  cin>>N>>K;
  segtree<int,mx,e> S(300001);
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    a--;
    S.set(a,S.prod(max(a-K,0LL),min(a+K+1,300001LL))+1);
  }
  cout<<S.prod(0,300001)<<endl;
}