//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
struct SegTree {
    typedef function<T(T, T)> OP;
    typedef function<void(T&, T)> UP;

    int N;
    vector<T> dat;
    OP op_;
    UP up_;
    T unit_;

    int get_n(int n) {
        int ret = 1;
        while (ret < n) ret <<= 1;

        return ret;
    }

    SegTree() : N(0) {}

    explicit SegTree(int n,
                     /// todo : ↓↓↓ edit from here ↓↓↓
                     OP op = [](T a, T b){ return max(a, b); },
                     UP up = [](T& a, T b){ a = b; },
                     T unit = 0)
                     : N(get_n(n)), dat(2 * N - 1, unit), op_(op), up_(up), unit_(unit) {}

    explicit SegTree(const vector<ll> &v,
                     /// todo : ↓↓↓ edit from here ↓↓↓
                     OP op = [](T a, T b){ return min(a, b); },
                     UP up = [](T& a, T b){ a = b; },
                     T unit = INF)
                     : N(get_n(v.size())), dat(2 * N - 1, unit), op_(op), up_(up), unit_(unit) {
        REP(i, v.size()) dat[N + i - 1] = v[i];
        for (int i = N - 2; i > -1; --i) dat[i] = _op(dat[2 * i + 1], dat[2 * i + 2]);
    }

    void init(int n, T val = 0) {
        N = get_n(n);
        dat.resize(2 * N - 1, val);
    }

    void update(int i, T v) {
        i += N - 1;
        up_(dat[i], v);

        while (i > 0) {
            i = (i - 1) / 2;
            dat[i] = op_(dat[2 * i + 1], dat[2 * i + 2]);
        }
    }

    // query for [a, b), k: current node id, [l, r): current range.
    ll query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = N;

        if (b <= l || r <= a) return unit_;
        if (a <= l && r <= b) return dat[k];

        int mid = (l + r) / 2;
        T c1 = query(a, b, 2 * k + 1, l, mid);
        T c2 = query(a, b, 2 * k + 2, mid, r);

        return op_(c1, c2);
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n, k; cin >> n >> k;

    vi a(n);
    REP(i, n) {
        cin >> a[i];
    }

    SegTree<int> st(300300);

    REP(i, n) {
        int m = st.query(max(0, a[i] - k), a[i] + k + 1);
        st.update(a[i], m + 1);
    }

    print(st.query(0, 300300));
}


Measured memory_bytes: 8488