#include <bits/stdc++.h>
using namespace std;
template <typename Mnd>
struct segment_tree {
  int sz;
  vector<Mnd> data;
  function<Mnd(Mnd, Mnd)> f;
  Mnd e;
  segment_tree(int _sz, function<Mnd(Mnd, Mnd)> _f, Mnd _e) : f(_f), e(_e) {
    sz = 1;
    while (sz < _sz) sz <<= 1;
    data.assign(sz * 2, e);
  }
  Mnd &operator[](const int &k) { return data[k + sz]; }
  void build() {
    for (int i = sz - 1; i > 0; i--) data[i] = f(data[2 * i], data[2 * i + 1]);
  }
  void update(int k, Mnd x) {
    data[k += sz] = x;
    while (k >>= 1) data[k] = f(data[2 * k], data[2 * k + 1]);
  }
  Mnd query(int a, int b) const {
    Mnd l = e, r = e;
    for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if (a & 1) l = f(l, data[a++]);
      if (b & 1) r = f(r, data[--b]);
    }
    return f(l, r);
  }
};
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  segment_tree<int> seg(
      300001, [](int a, int b) { return max(a, b); }, 0);
  for (int i = 0; i < n; i++) {
    int tmp = seg.query(max(0, a[i] - k), a[i] + k + 1) + 1;
    ans = max(ans, tmp);
    seg.update(a[i], max(seg[a[i]], tmp));
  }
  cout << ans << endl;
}
