#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 op1(int a, int b){
  return min(a, b);
}
int e1(){
  return 300005;
}
int target1;
bool f1(int a){
  return a > target1;
}
int op2(int a, int b){
  return max(a, b);
}
int e2(){
  return -1;
}
int target2;
bool f2(int a){
  return a < target2;
}

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,op1,e1> seg1(v);
  segtree<int,op2,e2> seg2(v);

  rep(i,N){
    target1 = v[i]+K;
    target2 = max(0, v[i]-K);

    int res1 = seg1.max_right<f1>(i+1);
    int res2 = seg2.max_right<f2>(i+1);

    nxt[i] = max(res1, res2);
  }

  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;
}
