#include<atcoder/all>
#include<iostream>
using namespace std;
using namespace atcoder;

int op(int a, int b) { return max(a, b); }
int e() { return 0; }

int main() {
  int N,K; cin>>N>>K;
  segtree<int, op, e> s(300010);
  int max_l = 0;
  for (int i = 0; i < N; i++) {
    int a;cin>>a;
    int prod = s.prod(max(0, a-K), min(300010, a+K+1));
    max_l = max(max_l, prod+1);
    s.set(a, prod+1);
  }
  cout<<max_l<<endl;
}