#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
template <class Monoid>
class SegmentTree {
 public:
  SegmentTree(size_t N, Monoid e, function<Monoid(Monoid, Monoid)> operation,
              function<Monoid(Monoid, Monoid)> updater)
      : e(e), operation(operation), updater(move(updater)) {
    n = 1;
    while (n < N) {
      n *= 2;
    }
    data = vector<Monoid>(2 * n - 1, e);
    for (int i = n - 2; i >= 0; i--) {
      data[i] = operation(data[2 * i + 1], data[2 * i + 2]);
    }
  }
  void update(int i, Monoid x) {
    i += n - 1;
    data[i] = updater(data[i], x);
    while (i > 0) {
      i = (i - 1) / 2;
      data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }
  Monoid query(int a, int b) { return query(a, b, 0, 0, n); }
  Monoid operator[](int i) { return data[i + n - 1]; }

 private:
  int n;
  vector<Monoid> data;
  Monoid e;
  function<Monoid(Monoid, Monoid)> operation;
  function<Monoid(Monoid, Monoid)> updater;
  Monoid query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return e;
    if (a <= l && r <= b) return data[k];
    Monoid c1 = query(a, b, 2 * k + 1, l, (l + r) / 2);
    Monoid c2 = query(a, b, 2 * k + 2, (l + r) / 2, r);
    return operation(c1, c2);
  }
};
void solve() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (ll i = 0; i < (ll)(N); i++) cin >> A[i];
  SegmentTree<ll> segmentTree(
      700000, -INF, [](ll a, ll b) { return max(a, b); },
      [](ll a, ll b) { return max(a, b); });
  segmentTree.update(0, 0);
  for (ll i = 0; i < (ll)(N); i++) {
    ll a = A[i];
    ll m1 = max(0LL, a - K);
    ll m2 = a + K;
    ll v = segmentTree.query(m1, m2 + 1);
    segmentTree.update(a, v + 1);
  }
  cout << segmentTree.query(0, 700000) << '\n';
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}
