#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);
template <typename T>
class segmenttree {
 private:
  int n;

 public:
  using F = function<T(T, T)>;
  T dif;
  F f;
  vector<T> st;
  segmenttree(int size, T init, F f) : f(f) {
    n = 1;
    while (n < size) {
      n *= 2;
    }
    st.assign(2 * n - 1, init);
  }
  void set(int i, T x) { st[i + n - 1] = x; }
  void build() {
    for (int i = n - 2; i >= 0; i--) {
      st[i] = f(st[i * 2 + 1], st[i * 2 + 2]);
    }
  }
  void update(int i, T x) {
    i += n - 1;
    st[i] = x;
    while (i > 0) {
      i = (i - 1) / 2;
      st[i] = f(st[2 * i + 1], st[2 * i + 2]);
    }
  }
  T query(int a, int b) { return query_(a, b, 0, 0, n); }
  T query_(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) {
      return dif;
    }
    if (a <= l && r <= b) {
      return st[k];
    } else {
      T x = query_(a, b, 2 * k + 1, l, (l + r) / 2);
      T y = query_(a, b, 2 * k + 2, (l + r) / 2, r);
      return f(x, y);
    }
  }
};
int main(void) {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  ll ma = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ma = max(ma, a[i]);
  }
  segmenttree<ll> s(ma + 1, 0, [](ll a, ll b) { return max(a, b); });
  ll ans = 0;
  s.build();
  for (int i = 0; i < n; i++) {
    ll l, r;
    l = max(a[i] - k, 0ll);
    r = min(a[i] + k + 1, ma + 1);
    ll x = s.query(l, r) + 1;
    s.update(a[i], x);
    ans = max(ans, x);
  }
  cout << ans << endl;
}
