#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
template <typename T>
struct RMQ {
  const T INF = 1e9;
  int n;
  vector<T> dat;
  RMQ(int n_) : n(), dat(n_ * 4, INF) {
    int tmp = 1;
    while (n_ > tmp) {
      tmp *= 2;
    }
    n = tmp;
  }
  void update(int k, T a) {
    k += n - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
    }
  }
  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return INF;
    if (a <= l && r <= b)
      return dat[k];
    else {
      T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
      T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
      return min(vl, vr);
    }
  }
};
int main() {
  int N, K;
  cin >> N >> K;
  int a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  RMQ<int> rmq(600005);
  rmq.update(a[0], -1);
  for (int i = 1; i < N; i++) {
    int res = rmq.query(max(-K + a[i], 0), K + a[i] + 1) - 1;
    rmq.update(a[i], res);
  }
  cout << -1 * rmq.query(0, 600004) << endl;
}
