#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
//using mint = modint1000000007;
//using mint = modint998244353;

int op(int a, int b){
  return min(a, b);
}
int e(){
  return 1000005;
}

int nxt[300005];
int dp[300005];

int main(){
  int N, K;
  cin >> N >> K;
  
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }
  segtree<int,op,e> seg(1000005);
  int base = 500000;
  for(int i=N-1; i>=0; i--){
    int x = v[i];
    int mn = x-K;
    int mx = x+K;
    int pos = seg.prod(base+mn, base+mx+1);
    if(pos == e()) nxt[i] = N;
    else nxt[i] = pos;

    seg.set(base+x, i);
  }

  rep(i,N){
    dp[i] = 1;
  }

  rep(i,N){
    dp[nxt[i]] = max(dp[nxt[i]], dp[i]+1);
  }
  int ret = 0;
  rep(i,N){
    ret = max(ret, dp[i]);
  }
  cout << ret << endl;
  
  return 0;
}

