#include <bits/stdc++.h>
using namespace std;

const int MOD = 1e9+7;
#define all(x) x.begin(), x.end()
#define rall (x) x.rbegin(), x.rend()
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int k;
const int maxi = 3e5+10;
int arr[maxi], tree[maxi*4];


template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A>
void debug_pq(A v) {
    bool first = true;
    string res = "{";
    while (!v.empty()){
        auto x = v.top();
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
        v.pop();
    }
    res += "}";
    cerr << res << "\n";
}

template <typename A>
void debug_que(A v) {
    bool first = true;
    string res = "{";
    while (!v.empty()){
        auto x = v.front();
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
        v.pop();
    }
    res += "}";
    cerr << res << "\n";
}


template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}


void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#define LOCAL

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


void update(int node, int st, int end, int ind, int val){
    if (st==end){
        arr[ind] = val;
        tree[node] = val;
    }
    else{
        int mid = (st+end)/2;
        if (st<=ind && ind<=mid){
            update(2*node, st, mid, ind, val);
        }
        else{
            update(2*node+1, mid+1, end, ind, val);
        }
        tree[node] = max(tree[2*node], tree[2*node+1]);
    }
}
int query(int node, int st, int end, int l, int r){
    if (st>r || end<l) return -10000000;
    if (l<=st && end<=r) return tree[node];
    int mid = (st+end)/2;
    int m1 = query(2*node, st, mid, l, r);
    int m2 = query(2*node+1, mid+1, end, l, r);
    return max(m1, m2);
}

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int n;
    cin >> n >> k;
    vector<int> values(n);
    for (auto &i: values)
        cin >> i;
    int ans = 0;
    for (int i=n-1; i>=0; i--){
        int l = max(0, values[i]-k), r = min(int(3e5), values[i]+k);
        int cur = query(1, 0, 3e5, l, r);
        ans = max(ans,cur+1);
        update(1, 0, 3e5, values[i], cur+1);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 9724