#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
struct S {
  int x;
  S() { x = 0; }
  S(int _x) : x(_x) {}
};
S op(S& a, S& b) { return {max(a.x, b.x)}; }
bool first(S) { return true; }
struct segtree {
  int _n;
  vector<S> t;
  int size;
  int log;
  segtree() : segtree(0) {}
  segtree(int n = -1) {
    if (n >= 0) init(n);
  }
  void init(int n) {
    _n = n;
    log = 0;
    while ((1U << log) < (unsigned int)(n)) log++;
    size = 1 << log;
    t.assign(2 * _n, S());
  }
  void build(vector<S> v) {
    init((int)v.size());
    assert(_n != 0);
    for (int i = 0; i < _n; i++) t[size + i] = v[i];
    for (int i = size - 1; i > 0; i--) t[i] = op(t[2 * i], t[2 * i + 1]);
  }
  void set(int p, S x) {
    assert(0 <= p && p < _n);
    p += size;
    t[p] = x;
    for (int i = 1; i <= log; i++)
      t[p >> i] = op(t[2 * (p >> i)], t[2 * (p >> i) + 1]);
  }
  S get(int p) {
    assert(0 <= p && p < _n);
    return t[p + size];
  }
  S query(int l, int r) {
    assert(0 <= l && l <= r && r <= _n);
    S ansl, ansr;
    l += size;
    r += size;
    while (l < r) {
      if (l & 1) ansl = op(ansl, t[l++]);
      if (r & 1) ansr = op(t[--r], ansr);
      l >>= 1;
      r >>= 1;
    }
    return op(ansl, ansr);
  }
  int max_right(int l) {
    assert(0 <= l && l <= _n);
    if (l == _n) return _n;
    l += size;
    S sm;
    do {
      while (l % 2 == 0) l >>= 1;
      if (!first(op(sm, t[l]))) {
        while (l < size) {
          l *= 2;
          if (first(op(sm, t[l]))) {
            sm = op(sm, t[l]);
            l++;
          }
        }
        return l - size;
      }
      sm = op(sm, t[l]);
      l++;
    } while ((l & -l) != l);
    return _n;
  }
  int min_left(int r) {
    assert(0 <= r && r <= _n);
    if (r == 0) return 0;
    r += size;
    S sm;
    do {
      r--;
      while (r > 1 && (r % 2)) r >>= 1;
      if (!first(op(t[r], sm))) {
        while (r < size) {
          r = (2 * r + 1);
          if (first(op(t[r], sm))) {
            sm = op(t[r], sm);
            r--;
          }
        }
        return r + 1 - size;
      }
      sm = op(t[r], sm);
    } while ((r & -r) != r);
    return 0;
  }
};
const int N = 6e5 + 7;
void solve() {
  int n, k;
  cin >> n >> k;
  ;
  vi a(n);
  for (ll i = 0; i < n; i++) cin >> a[i];
  ;
  segtree T(N);
  for (ll i = 0; i < (n); i++) {
    S second = T.query(max(a[i] - k, 0), a[i] + k + 1);
    T.set(a[i], {second.x + 1});
  }
  cout << T.query(0, n).x << endl;
  ;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  while (t--) {
    solve();
  }
}
