signed main(){
  ios_base::sync_with_stdio(0); 
  cin.tie(0);
  // freopen("FDT.txt", "r", stdin);
  lazy_segment_tree tr;
  int n, k;
  cin >> n >> k;
  tr.init(300000);
  vector<int> a(n + 1);
  for(int i = 1; i <= n; i ++) cin >> a[i];
  for(int i = n; i >= 1; i --){
    int lf = a[i] - k;
    if(lf < 0) lf = 0;
    int rt = a[i] + k;
    if(rt > 300000) rt = 300000;
    int d = tr.get(1, 1, 300000, lf, rt);
    if(d < 0) d = 0;
    d ++;
    tr.update(1, 1, 300000, a[i], a[i], d);
  }
  cout << tr.get(1, 1, 300000, 0, 300000);
}
