#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

template<class T> 
ostream& operator<<(ostream &os, vector<T> input) {
    os << "[ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "]";
}

template<class T> 
ostream& operator<<(ostream &os, set<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, unordered_set<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, multiset<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, unordered_multiset<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class L, class R> 
ostream& operator<<(ostream &os, map<L,R> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << "(" << elem.first << "," << elem.second << ") ";
	}
	return os << "}";
}

template<class L, class R> 
ostream& operator<<(ostream &os, unordered_map<L,R> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << "(" << elem.first << "," << elem.second << ") ";
	}
	return os << "}";
}

#define ll long long
const int MAXN = 500005;
const int INF = 1e9;
const int MOD = 998244353;
const int N = MAXN;

long long maxi[4*N];
void update(int b,int e,int node,int i,int j,ll delta){
    if( b > j || e < i) return;
    if( i <= b && e<= j){
		maxi[node] = delta;
    }else{
        int mid = (b+e)>>1 , le = 2*node + 1 , ri = le +1;
        update(b,mid,le,i,j,delta);
        update(mid+1,e,ri,i,j,delta);
        maxi[node] = max(maxi[le], maxi[ri]);
    }
}

long long query(int b,int e,int node,int i,int j){
    if( i <= b && e <= j) return maxi[node];

    int mid = (b+e)>>1 , le = 2*node + 1 , ri = le + 1;
    if(mid < i) return query(mid+1,e,ri,i,j);
    else
        if(mid+1 > j) return query(b,mid,le,i,j);
        else{
            long long res = max(query(b,mid,le,i,j) ,query(mid+1,e,ri,i,j));
        return res;
        }
}

class TaskD {
private:


public:
	void solveOne(int it){
		int n, k;
		cin >> n >> k;
		vector<int> nums(n);
		vector<pair<int,int>> ord;
		for(int i = 0; i < n; i++) {
			cin >> nums[i];
			ord.push_back({nums[i], i});
		}
		sort(ord.begin(), ord.end());
		int ans = 0;
		for(int i = 0; i < n; i++) {
			int le = lower_bound(ord.begin(), ord.end(), make_pair(nums[i]-k, -1)) - ord.begin();
			int ri = upper_bound(ord.begin(), ord.end(), make_pair(nums[i]+k, n+1)) - ord.begin();
			ri--;
			if(le <= ri) {
				int maxi = query(0, n-1, 0, le, ri);
				ans = max(ans, 1 + maxi);
				int pos = lower_bound(ord.begin(), ord.end(), make_pair(nums[i], i)) - ord.begin();
				update(0, n-1, 0, pos, pos, 1 + maxi);
			}
		}
		cout << ans << endl;
		
	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskD solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 15180