#include<bits/stdc++.h>
#include<atcoder/all>
#define ll long long int
using namespace atcoder;
using namespace std;

const int MAX_A = 300005;
                                               
int op(int a, int b){ return max(a, b);}
int e(){return 0;}
 
int main(){
  int n, k;
  cin >> n >> k;
  
  vector<int> a(n);
  for (int i=0; i<n; i++) cin >> a[i];
  
  segtree<int, op, e> dp(MAX_A);
  for (int i=0; i<n; i++){
  	int x = a[i];
    int l = x-k;
    int r = x+k+1;
    l = max(l, 0);
    r = min(r, MAX_A);
    int now = dp.prod(l, r)+1;
    dp.set(i, now);
  }
  
  cout <<  dp.prod(0, MAX_A) << endl;
}