#include <bits/stdc++.h>
#include <atcoder/segtree>
using namespace std;
using namespace atcoder;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
using P = pair<int,int>;
int op(int a, int b){
   return max(a,b);
}
int e(){
   return (int)(0);
}
segtree<int,op,e> seg(30001);
int main() {
   int n,k;cin>>n>>k;
   rep(i,n){
      int a;cin>>a;
      seg.set(a,seg.prod(max(1,a-k),min(n,a+k+1))+1);
   }
   cout<<seg.all_prod()<<endl;
}