#include <bits/stdc++.h>

using namespace std;

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
//const int mod = 1000000007;
const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

//第二引数にfalseを入れると最大値取得
struct SegmentTree {
  private:
  int n;
  int sz;
  vector<ll> node;
  bool is_min;
  public:
  SegmentTree(vector<ll> v, bool flag = true) {
    sz = v.size();
    is_min = flag;
    n = 1; while(n < sz) n *= 2;
    node.resize(2*n-1, (is_min ? 1 : -1) * INF64);
    for(int i = 0; i < sz; ++i) node[i+n-1] = v[i];
    for(int i = n-2; i >= 0; --i) {
      if(is_min) node[i] = min(node[2*i+1], node[2*i+2]);
      else node[i] = max(node[2*i+1], node[2*i+2]);
    }
  }
  void update(int x, ll val) {
    x += (n-1);
    node[x] = val;
    while(x > 0) {
      x = (x-1)/2;
      if(is_min) node[x] = min(node[2*x+1], node[2*x+2]);
      else node[x] = max(node[2*x+1], node[2*x+2]);
  }
  }
  //[a, b) 区間の最大／最小値
  ll get_val(int a, int b, int k = 0, int l = 0, int r=-1) {
    if(r < 0) r = n;
    if(r <= a || b <= l) return (is_min ? 1 : -1) * INF64;
    if(a <= l && r <= b) return node[k];
    ll vl = get_val(a, b, 2*k+1, l, (l+r)/2);
    ll vr = get_val(a, b, 2*k+2, (l+r)/2, r);
    if(is_min) return min(vl, vr);
    else return max(vl, vr);
  }
  vector<ll> get_vec() {
    vector<ll> res;
    rep(i, sz) res.push_back(node[i+n-1]);
    return res;
  }
  ll get_node(int x) {
    return node[x+n-1];
  }
};

int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  SegmentTree dp(vector<ll>(300004, 0), false);
  rep(i, n) {
    int l = max(0, a[i]-k);
    int r = min(300000, a[i]+k);
    int x = dp.get_val(l, r+1);
    dp.update(a[i], x+1);
  }
  cout << dp.get_val(0, 300001) << endl;
}

Measured memory_bytes: 14848