#include <bits/stdc++.h>
using namespace std;
class segmenttree {
 private:
  int n;
  long long identity = 0;
  std::vector<long long> dat;

 public:
  void init(int N) {
    n = 1;
    while (n < N) n *= 2;
    dat.clear();
    for (int i = 0; i < 2 * n - 1; ++i) {
      dat.push_back(identity);
    }
  }
  long long calc();
  void update(int k, long long a) {
    k += n - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = calc(dat[2 * k + 1], dat[2 * k + 2]);
    }
  }
  long long query(long long a, long long b) {
    a += n;
    b += n;
    long long R = 0;
    while (a < b) {
      if (a % 2 == 1) {
        R = calc(R, dat[a - 1]);
        a += 1;
      }
      a /= 2;
      if (b % 2 == 1) {
        b -= 1;
        R = calc(R, dat[b - 1]);
      }
      b /= 2;
    }
    return R;
  }
  long long calc(long long a, long long b) { return max(a, b); }
};
int main(void) {
  long long N, K, a;
  vector<long long> A;
  cin >> N >> K;
  for (long long i = 0; i < (N); ++i) {
    cin >> a;
    A.push_back(a);
  }
  segmenttree seg;
  seg.init(314514);
  for (long long i = 0; i < (N); ++i) {
    a = A[i];
    long long l = max(0ll, a - K);
    long long r = min(314514ll, a + K + 1);
    long long D = seg.query(l, r);
    seg.update(a, D + 1);
  }
  long long Ans = seg.query(0, N);
  cout << Ans << endl;
  return 0;
}
