#include <bits/stdc++.h>
using namespace std;
using llong = long long int;
const static int MOD = 1000000007;
const static int INF = 1 << 30;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};
template <typename Monoid>
struct SegmentTree {
  using F = function<Monoid(Monoid, Monoid)>;
  int sz;
  vector<Monoid> seg;
  const F f;
  const Monoid M1;
  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while (sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }
  void set(int k, const Monoid &x) { seg[k + sz] = x; }
  void build() {
    for (int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while (k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if (a & 1) L = f(L, seg[a++]);
      if (b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }
  Monoid operator[](const int &k) const { return seg[k + sz]; }
};
int main(int argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k, max_N = 300001;
  cin >> n >> k;
  vector<int> A(n);
  for (int i = 0; i < n; ++i) cin >> A[i];
  SegmentTree<int> dp(
      max_N, [](int a, int b) { return max(a, b); }, 0);
  dp.build();
  int left, right;
  int now, tmp;
  for (int i = 0; i < n; ++i) {
    left = max(A[i] - k, 0), right = min(A[i] + k + 1, max_N);
    now = dp.query(i, i + 1);
    tmp = dp.query(left, right);
    dp.update(i, max(now, tmp + 1));
  }
  int ans = 1;
  for (int i = 0; i < n; ++i) ans = max(ans, dp.query(i, i + 1));
  cout << ans << endl;
  return 0;
}
