#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
struct RMQ {
  int n;
  const T ex = 0;
  vector<T> dat;
  RMQ(vector<T> v) {
    int x = 1;
    int i;
    n = v.size();
    while (x < n) x <<= 1;
    n = x;
    dat.resize(2 * n - 1, ex);
    for (i = 0; i < v.size(); ++i) {
      dat.at(i + n - 1) = v.at(i);
    }
    for (i = n - 2; i >= 0; --i) {
      dat.at(i) = calculate(dat.at(2 * i + 1), dat.at(2 * i + 2));
    }
  }
  T calculate(T a, T b) { return max(a, b); }
  void update(int ind, T x) {
    ind += n - 1;
    dat.at(ind) = x;
    while (ind > 0) {
      ind = (ind - 1) / 2;
      dat.at(ind) = calculate(dat.at(2 * ind + 1), dat.at(2 * ind + 2));
    }
  }
  T query(int a, int b) { return query_sub(a, b, 0, 0, n); }
  T query_sub(int a, int b, int now, int l, int r) {
    if (r <= a || b <= l)
      return ex;
    else if (a <= l && r <= b)
      return dat.at(now);
    else {
      T vl = query_sub(a, b, 2 * now + 1, l, (l + r) / 2);
      T vr = query_sub(a, b, 2 * now + 2, (l + r) / 2, r);
      return calculate(vl, vr);
    }
  }
};
int main() {
  ll i, j;
  ll n, k;
  cin >> n >> k;
  ll INF = 3e5 + 1;
  vector<ll> ini(INF, 0);
  RMQ<ll> seg(ini);
  for (i = 0; i < n; ++i) {
    ll a;
    cin >> a;
    ll left = max(a - k, 0ll);
    ll right = min(a + k + 1, INF);
    ll tmp = seg.query(left, right + 1);
    seg.update(a, tmp + 1);
  }
  cout << seg.query(0, INF) << endl;
  return 0;
}
