#include <iostream>
#include <atcoder/segtree>

#define MAX_N (300000)

int op(int a, int b) {
  return std::max<int>(a, b);
}

int e() {
  return 0;
}

int main() {
  int N, K;
  std::cin >> N >> K;
  std::vector<int> A(N);
  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  atcoder::segtree<int,op,e> seg(MAX_N);
  for (int i = N - 1; i >= 0; i--) {
    int len = seg.prod(std::max<int>(0,A[i]-K), std::min<int>(MAX_N,A[i]+K+1));
    seg.set(A[i], len + 1);
  }
  std::cout << seg.all_prod() << std::endl;
  return 0;
}
