//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

template<class Monoid>
class segtree {
    using T = typename Monoid::value_type;
    
    int n;
    vector<T> val;

public:
    constexpr segtree(int _n, vector<T> init = vector<T>()) {
        n = 1;
        while (n < _n) n *= 2;
        val = vector<T>(2 * n, Monoid::identity);
        if (init.size()) rep(i, _n) val[i + n] = init[i];
        rrep(i, n) val[i] = Monoid::operate(val[i * 2], val[i * 2 + 1]);
    }
    
    // segment [l,r)
    T fold(int l, int r) {
        l += n, r += n;
        T fold_l = Monoid::identity;
        T fold_r = Monoid::identity;
        while (l < r) {
            if (l & 1) fold_l = Monoid::operate(fold_l, val[l++]);
            if (r & 1) fold_r = Monoid::operate(val[--r], fold_r);
            l >>= 1, r >>= 1;
        }
        return Monoid::operate(fold_l, fold_r);
    }
    
    template<class F>
    void update(int i, const F &f) {
        i += n;
        val[i] = f(val[i]);
        while (i > 1) {
            i >>= 1;
            val[i] = Monoid::operate(val[i * 2], val[i * 2 + 1]);
        }
    }
};

class Node {
public:
    using value_type = int;
    
    value_type value;
    
    Node(value_type value) : value(value) {}
    
    static constexpr value_type identity = inf;
    
    static constexpr value_type operate(const value_type &l, const value_type &r) {
        return min(l, r);
    }
};

int dp[300010];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vi a(n);
    cin >> a;
    segtree<Node> st(300001);
    vi u(n), d(n);
    rrep(i, n) {
        u[i] = st.fold(a[i], min(a[i] + k, 300000) + 1);
        d[i] = st.fold(max(a[i] - k, 0), a[i] + 1);
        st.update(a[i], [&](auto) { return i; });
    }
    int ans = 0;
    rep(i, n) {
        chmax(dp[i], 1);
        if (u[i] < n) chmax(dp[u[i]], dp[i] + 1);
        if (d[i] < n) chmax(dp[d[i]], dp[i] + 1);
        chmax(ans, dp[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 12108