#include <bits/stdc++.h>
using namespace std;
using ll = long long;
class Segtree {
 private:
  ll N = -1;
  vector<ll> data;
  function<ll(ll, ll)> func;
  ll e_id;

 public:
  Segtree(ll n_, function<ll(ll, ll)> f, ll e) {
    func = f;
    e_id = e;
    ll N_ = 1;
    while (N_ < n_) N_ *= 2;
    N = N_;
    data.resize(2 * N - 1, e_id);
  }
  void update(ll k, ll a) {
    k += N - 1;
    data[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      data[k] = func(data[k * 2 + 1], data[k * 2 + 2]);
    }
  }
  ll query_sub(ll a, ll b, ll k, ll l, ll r) {
    if (r <= a || b <= l) {
      return 0;
    } else if (a <= l && r <= b) {
      return data[k];
    } else {
      ll vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
      ll vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
      return func(vl, vr);
    }
  }
  ll query(ll a, ll b) {
    if (b < a) swap(a, b);
    return query_sub(a, b + 1, 0, 0, N);
  }
};
signed main() {
  ll N, K;
  cin >> N >> K;
  auto fx = [](ll x1, ll x2) -> ll { return max(x1, x2); };
  ll e = -1;
  Segtree RMQ(N, fx, e);
  vector<ll> vec(N);
  for (ll i = 0; i < (ll)(N); i++) {
    cin >> vec[i];
    vec[i]--;
  }
  for (ll i = 0; i < N; i++) {
    ll left = max(ll(0), vec[i] - K);
    ll right = min(N - 1, vec[i] + K);
    ll M = RMQ.query(left, right);
    RMQ.update(vec[i], M + 1);
  }
  cout << RMQ.query(0, N - 1) << "\n";
  system("PAUSE");
}
