#include <bits/stdc++.h>
int main() {
  using namespace std;
  unsigned long N, K;
  cin >> N >> K;
  constexpr unsigned long Amax = 524288;
  vector<unsigned long> sgt(2 * (Amax + 1));
  const auto& upd = [&sgt](unsigned long i, unsigned long x) {
    i += Amax + 1;
    do sgt[i] = x;
    while (i >>= 1);
  };
  const auto& fold = [&sgt](unsigned long L, unsigned long R) {
    L += Amax + 1;
    R += Amax + 1;
    unsigned long ret{0};
    while (L < R) {
      if (L & 1) {
        ret = max(ret, sgt[L]);
        ++L;
      }
      if (R & 1) {
        --R;
        ret = max(ret, sgt[R]);
      }
      L >>= 1;
      R >>= 1;
    }
    return ret;
  };
  for (unsigned long i{0}, A; i < N; ++i) {
    cin >> A;
    upd(A, fold(max(K, A) - K, min(A + K, Amax) + 1) + 1);
  }
  cout << fold(0, Amax + 1) << endl;
  return 0;
}
