/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <limits>//setprecision
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#include <numeric> //accumulate,,,
#define endl "\n";
using namespace std;

const long long INF = 4000000000000000001;
const int inf = 1001001001;
long long MOD = 1000000007;

void chmax(long long &a,long long b){if(a < b) a = b;}
void chmin(long long &a,long long b){if(a > b) a = b;}

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % MOD;
    return res %= MOD;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a; else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

//0-indexed
vector<long long> segment;
long long Size_beki2 = 1;
void initialization(int N){
    //初期化をする（二分木を作る）
    while(Size_beki2 < N) Size_beki2 *= 2;
    segment = vector<long long>(2*Size_beki2-1,0);
}
void update(int P,long long X){
    //二分木の下からたどっていく
    P += Size_beki2-1;
    segment.at(P) = X;
    while(P > 0){
        //一つ上へ
        P = (P-1)/2;
        segment.at(P) = max(segment.at(P*2+1),segment.at(P*2+2));
    }
}
//[left,right)の最大値を再帰的に求める（二分木の上から特定していく感じ）（半開区間なので0-indexedのrightは+1する）
long long query(int left,int right,int P,int l,int r){
    if(r <= left || right <= l) return 0;//完全に外は関係ない
    if(left <= l && r <= right) return segment.at(P);//完全に含まれる
    else{
        long long mini_left = query(left,right,(P << 1)+1,l,(l+r) >> 1);
        long long mini_right = query(left,right,(P << 1)+2,(l+r) >> 1,r);
        return max(mini_left,mini_right);
    }
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N;cin >> N;int K;cin >> K;
    vector<int> retu(N);
    int maxi = 0;
    for(int i = 0;i<N;i++) cin >> retu.at(i),maxi = max(maxi,retu.at(i));
    initialization(300005);
    reverse(retu.begin(),retu.end());
    for(int i = 0;i<N;i++){
        int now = retu.at(i);
        int MAX = query(max(now-K,0),min(now+K+1,maxi+1),0,0,Size_beki2);
        /*for(int j = 1;j<=9;j++){
            cout << segment.at(j+Size_beki2-1) << " ";
        }*/
        //cout << "|" << now << " ";
        //cout << MAX << " ";
        update(now,MAX+1);
        //cout << segment.at(now+Size_beki2-1) << endl;
        
    }
    int ans = 0;
    for(int i = 0;i<300005;i++){
        ans = max(ans,(int)segment.at(i));
    }
    cout << ans << endl;
}


Measured memory_bytes: 12708