#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
typedef long long ll;
int op(int a, int b) {
    return max(a, b);
}
 
int e() {
    return (int)(0);
}
int main(){
  ll n,k;
  cin>>n>>k;
  segtree<int,op,e>seg(n+1);
  ll ans=0;
  for(int i=0;i<n;i++){
    ll a; cin >> a;
        ll p = seg.prod(max(0,a-k),min(N+1,a+k+1))+1;
        seg.set(a,p);
        ans = max(ans,p);
  }
  cout<<ans<<"\n";
}
