#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<long long, long long>;
const long double pi = acos(-1.0);
const long long MAX = 1000010;
const long long INF = 1ll << 60;
const long long MOD = 1000000007;
template <typename T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
inline void print(P a) { cout << a.first << " " << a.second << endl; }
template <typename T>
T bpow(T a, ll n) {
  T r(1);
  while (n) {
    if (n & 1) r *= a;
    a *= a;
    n >>= 1;
  }
  return r;
}
struct faster_io {
  faster_io() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
  }
} faster_io_;
template <typename X>
struct SegTree {
  using F = function<X(X, X)>;
  long long n;
  F f;
  const X ex;
  vector<X> dat;
  SegTree(long long n_, F f_, X ex_) : n(), f(f_), ex(ex_), dat(n_ * 4, ex_) {
    long long x = 1;
    while (n_ > x) {
      x *= 2;
    }
    n = x;
  }
  void set(long long i, X x) {
    dat[i + n - 1] = x;
    return;
  }
  void build() {
    for (long long k = (long long)(n - 1 - 1); k >= 0; k--)
      dat[k] = f(dat[2 * k + 1], dat[2 * k + 2]);
    return;
  }
  void update(long long i, X x) {
    i += n - 1;
    dat[i] = x;
    while (i) {
      i = (i - 1) / 2;
      dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]);
    }
    return;
  }
  X query(long long a, long long b) { return query_sub(a, b, 0, 0, n); }

 private:
  X query_sub(long long a, long long b, long long k, long long l, long long r) {
    if (r <= a || b <= l)
      return ex;
    else if (a <= l && r <= b)
      return dat[k];
    else {
      X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
      X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
      return f(vl, vr);
    }
  }
};
signed main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (long long i = 0; i < (long long)(n); i++) cin >> a[i];
  using X = long long;
  auto f = [](X x1, X x2) -> X { return max(x1, x2); };
  X ex = 0;
  SegTree<X> seg(300003, f, ex);
  for (long long i = 0; i < (long long)(n); i++) {
    long long x = a[i];
    long long l = max(x - k, 0ll);
    long long r = min(x + k + 1, 300003ll);
    long long now = seg.query(l, r) + 1;
    seg.update(x, now);
  }
  cout << seg.query(0, 30003) << endl;
  return 0;
}
