#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
struct SegmentTree {
 private:
  ll n;
  vector<ll> node;

 public:
  SegmentTree(vector<ll> v) {
    ll sz = v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1, INF);
    for (ll i = 0; i < sz; i++) node[i + n - 1] = v.at(i);
    for (ll i = n - 2; i >= 0; i--)
      node[i] = min(node[2 * i + 1], node[2 * i + 2]);
  }
  void update(ll x, ll val) {
    x += (n - 1);
    node[x] = val;
    while (x > 0) {
      x = (x - 1) / 2;
      node[x] = min(node[2 * x + 1], node[2 * x + 2]);
    }
  }
  ll getor(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return INF;
    if (a <= l && r <= b) return node[k];
    ll vl = getor(a, b, 2 * k + 1, l, (l + r) / 2);
    ll vr = getor(a, b, 2 * k + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  ll n, k;
  cin >> n >> k;
  vector<ll> vec(n);
  for (ll i = 0; i < (ll)(n); i++) cin >> vec[i];
  vector<ll> dp(3e5 + 1);
  SegmentTree tree(dp);
  for (ll i = 0; i < (ll)(n); i++) {
    ll Max = -tree.getor(max(0LL, vec[i] - k), min((ll)3e5, vec[i] + k));
    tree.update(vec[i], -(Max + 1));
  }
  cout << -tree.getor(0, 3e5 + 1) + 1 << endl;
}
