#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 3e5 + 5, inf = 4e18, mod = 1e9 + 7;
ll n, k, a[N], seg[N * 4], dp[N];
ll get(ll l, ll r, ll v = 1, ll s = 0, ll e = n) {
  if (l >= e || r <= s) return -inf;
  if (l <= s && e <= r) return seg[v];
  ll mid = (e + s) / 2, lc = v + v, rc = lc + 1;
  return max(get(l, r, lc, s, mid), get(l, r, rc, mid, e));
}
void fix(ll p, ll x, ll v = 1, ll s = 0, ll e = n) {
  if (e - s == 1) {
    if (seg[v] < x) seg[v] = x;
    return;
  }
  ll mid = (e + s) / 2, lc = v + v, rc = lc + 1;
  if (p < mid)
    fix(p, x, lc, s, mid);
  else
    fix(p, x, rc, mid, e);
  seg[v] = max(seg[lc], seg[rc]);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ll b = 300 * 1000;
    ll x = min(b, a[i] + k), y = max(b - b, a[i] - k);
    ll z = get(y, x + 1);
    cout << " i : " << i << " z : " << z << endl;
    dp[i] = z + 1;
    fix(a[i], dp[i]);
    if (i > 0) dp[i] = max(dp[i - 1], dp[i]);
  }
  cout << dp[n - 1];
  cout << endl;
}
