#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define setp(x) fixed << setprecision(x)
#define ordered_set tree<pair<long double, int> , null_type,less<pair<long double, int> >, rb_tree_tag,tree_order_statistics_node_update> 
 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const ll INF = ll(1e16);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
} 
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r; 
}
template<typename T_vector> // neal
void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = int(v.size());
 
    for (int i = start; i < end; i++)
        cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}
int used[N];
vector<int> g[N];
void dfs(int v){
	used[v] = 1;
	for(int to : g[v]) if(!used[to]) dfs(to);

}
struct segtree
{
	vector<long long> T;
	vector<long long> add;
	void init(int n){
		T.resize(4 * n + 1);
		add.resize(4 * n + 1);
	}
	long long merge(long long x, long long y){
		return max(x, y);
	}
	void push(int v){
		T[v * 2] += add[v];
		T[v * 2 + 1] += add[v];
		add[v * 2] += add[v];
		add[v * 2 + 1] += add[v];
		add[v] = 0; 
	}
	void updval(int v, int tl, int tr, int pos, int val){
		if(tl == tr)  T[v] = max(T[v], 1ll * val);
		else{
			int tm = tl + tr >> 1;
			if(pos <= tm) updval(2 * v, tl, tm, pos, val);
			else updval(2 * v + 1, tm + 1, tr, pos, val);
			T[v] = merge(T[v * 2], T[v * 2 + 1]);
		}
	}
	long long get(int v, int tl, int tr, int l, int r){
		if(l <= tl && tr <= r) return T[v];
		if(l > tr || r < tl) return 0;
		push(v);
		int tm = tl + tr >> 1;
		return merge(get(2 * v, tl, tm, l, r),
		get(2 * v + 1, tm + 1, tr, l, r));
	}
} T;
int dp[N];
void solve(){
	int n, k;
	cin >> n >> k;
	int a[n];
	stack<int> st;
	T.init(300001);
	rep(i, n){
		cin >> a[i];
		int l = max(0, a[i] - k);
		int r = min(300000, a[i] + k);
		int t = T.get(1, 0, 300000, l, r);
		T.updval(1, 0, 300000, a[i], t + 1);
	}
	cout << T.T[1];

}

	


int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
    Red;
  	int T = 1;
  	// cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

Measured memory_bytes: 46828