#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7, N = 3e5 + 1;
ll t[4 * N];
vector<ll> a(4 * N, MOD);
void build(ll v, ll tl, ll tr) {
  if (tl == tr) {
    t[v] = a[tl];
  } else {
    ll tm = (tl + tr) / 2;
    build(v * 2, tl, tm);
    build(v * 2 + 1, tm + 1, tr);
    t[v] = min(t[v * 2], t[v * 2 + 1]);
  }
}
ll sum(ll v, ll tl, ll tr, ll l, ll r) {
  if (l > r) return MOD;
  if (l == tl && r == tr) {
    return t[v];
  }
  ll tm = (tl + tr) / 2;
  return min(sum(v * 2, tl, tm, l, min(r, tm)),
             sum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
void update(ll v, ll tl, ll tr, ll pos, ll new_val) {
  if (tl == tr) {
    t[v] = new_val;
  } else {
    ll tm = (tl + tr) / 2;
    if (pos <= tm)
      update(v * 2, tl, tm, pos, new_val);
    else
      update(v * 2 + 1, tm + 1, tr, pos, new_val);
    t[v] = min(t[v * 2], t[v * 2 + 1]);
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, k;
  cin >> n >> k;
  vector<ll> A(n);
  for (ll i = 0; i < n; ++i) {
    cin >> A[i];
  }
  vector<ll> MN(N, MOD);
  vector<ll> dp(n);
  dp[n - 1] = 1;
  build(1, 0, N - 1);
  update(1, 0, N - 1, A[n - 1], n - 1);
  for (ll i = n - 2; i >= 0; --i) {
    ll mn = max(0ll, A[i] - k);
    ll mx = min(N - 1, A[i] + k);
    ll q = sum(1, 0, N - 1, mn, mx);
    42;
    if (q == MOD) {
      dp[i] = 1;
    } else {
      dp[i] = dp[q] + 1;
    }
    update(1, 0, N - 1, A[i], i);
  }
  cout << *max_element(dp.begin(), dp.end()) << '\n';
  return 0;
}
