#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
struct node {
  int l, r;
  long long x, lazy;
  node() {}
  node(int _l, int _r) : l(_l), r(_r), x(0), lazy(0) {}
  node(int _l, int _r, long long _x) : node(_l, _r) { x = _x; }
  node(node a, node b) : node(a.l, b.r) { x = a.x + b.x; }
  void update(long long v) { x = v; }
  void range_update(long long v) { lazy = v; }
  void apply() {
    if (lazy != 0) x = lazy * (r - l + 1);
    lazy = 0;
  }
  void push(node &u) {
    if (lazy != 0) u.lazy = lazy;
  }
};
struct segment_tree {
  int n;
  vector<node> arr;
  segment_tree() {}
  segment_tree(const vector<long long> &a) : n(a.size()), arr(4 * n) {
    mk(a, 0, 0, n - 1);
  }
  node mk(const vector<long long> &a, int i, int l, int r) {
    int m = (l + r) / 2;
    return arr[i] = l > r    ? node(l, r)
                    : l == r ? node(l, r, a[l])
                             : node(mk(a, 2 * i + 1, l, m),
                                    mk(a, 2 * i + 2, m + 1, r));
  }
  node update(int at, long long v, int i = 0) {
    propagate(i);
    int hl = arr[i].l, hr = arr[i].r;
    if (at < hl || hr < at) return arr[i];
    if (hl == at && at == hr) {
      arr[i].update(v);
      return arr[i];
    }
    return arr[i] = node(update(at, v, 2 * i + 1), update(at, v, 2 * i + 2));
  }
  node query(int l, int r, int i = 0) {
    propagate(i);
    int hl = arr[i].l, hr = arr[i].r;
    if (r < hl || hr < l) return node(hl, hr);
    if (l <= hl && hr <= r) return arr[i];
    return node(query(l, r, 2 * i + 1), query(l, r, 2 * i + 2));
  }
  node range_update(int l, int r, long long v, int i = 0) {
    propagate(i);
    int hl = arr[i].l, hr = arr[i].r;
    if (r < hl || hr < l) return arr[i];
    if (l <= hl && hr <= r) return arr[i].range_update(v), propagate(i), arr[i];
    return arr[i] = node(range_update(l, r, v, 2 * i + 1),
                         range_update(l, r, v, 2 * i + 2));
  }
  void propagate(int i) {
    if (arr[i].l < arr[i].r)
      arr[i].push(arr[2 * i + 1]), arr[i].push(arr[2 * i + 2]);
    arr[i].apply();
  }
};
int main() {
  cin.sync_with_stdio(false);
  int n, k, mx = 0;
  cin >> n >> k;
  vector<int> a(n);
  for (auto i = (0); i < (n); ++i) cin >> a[i];
  vector<long long> jnk(300001, 0);
  segment_tree st(jnk);
  for (int i = n - 1; i >= 0; --i) {
    int lo = max(0, a[i] - k);
    int hi = min(300000, a[i] + k);
    int bst = st.query(a[i], a[i]).x + 1;
    mx = max(mx, bst);
    st.range_update(lo, hi, bst);
  }
  cout << mx << endl;
}
