#include <atcoder/lazysegtree>
#include <cstdio>

using namespace std;
using namespace atcoder;


using ll = long long;
const ll MAX = 3e5+10;

ll op(ll l, ll r) { return ll{max(l,r)}; }

ll e() { return ll{0}; }

ll mapping(ll l, ll r) { return ll{max(r , l)};}; 

ll composition(ll l, ll r) { return ll{max(r,l)};}; 

ll id() { return ll{0};};

int main() {
  ll n,k,ans=0;
  cin >> n >> k;

  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  lazy_segtree<ll, op, e, ll, mapping, composition, id> seg(
      vector<ll>(MAX,0));
  for(int i=0;i<n;i++){
    ll val = seg.get(a[i]);
    val++;
    ans = max(ans,val);
    ll l = min(MAX,max(1ll,a[i]-k));
    ll r = min(MAX,a[i]+k) + 1;
    seg.apply(l,r,val);
  }
  cout << ans << endl;
}
