

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

#include <atcoder/all>

using namespace atcoder;
//typedef modint998244353 mint;

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

int e() { return -1; }

int target;

bool f(int v) { return v < target; }

int main(){
  int N,K;
  cin>>N>>K;
  VI A(N);
  rep(i,N) cin>>A[i];
  segtree<int,op,e> S(300003);
  rep(i,30003) S.set(i,0);
  rep(i,N){
    int L=max(0,A[i]-K);
    int R=min(300000,A[i]+K);
    S.set(A[i],S.prod(L,R+1)+1);
  }
  cout<<S.all_prod()<<endl;
}
