#include<bits/stdc++.h>
#include <iostream>
#include<map>
#include <algorithm>
using namespace std;
typedef long long      ll;
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define cena           ios_base::sync_with_stdio(false);cin.tie(NULL);
int t=1000001;
#define MOD  1000000007
class myData
{
    public:
    int t;
    int x;
    int y;
    int d;
    myData(int t,int x,int y,int d)
    : t(t),x(x),y(y),d(d)
    {
    }
    bool operator<(const myData& a) const
    {
        return (this->t < a.t);
    }
};
ll exponentMod(ll A, ll B)
{
    if (A == 0)
        return 0;
    if (B == 0)
        return 1;
    ll y;
    if (B % 2 == 0) {
        y = exponentMod(A, B / 2);
        y = (y * y) ;
    }
    else {
        y = A ;
        y = (y * exponentMod(A, B - 1) );
    }
    return (ll)((y ));
}
pair<int,int>  factorize(ll n) {
    int ans=1;
    int c=0;
    for (ll i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            if(i!=2)
                ans*=i,c++;
            n/=i;
        }
    }
    if (n != 1) {
            if(n!=2)
        ans*=n,c++;
    }
    return {ans,c};
}
////////////    FENWICK TREE    //////////////////
map<ll,ll> bit;
int N1= 2e5;
void update(ll i){
    for(;i<=N1;i+=i&(-i))
        bit[i]++;
}
ll get(ll i){
    ll ans = 0;
    for(;i>0;i-=i&(-i))
        ans+=bit[i];
    return ans;
}
int now;
bool sortByVal(const myData &a,
               const myData &b)
{
    return (a.t<b.t);
}/*char s[1005][1005];
int vis[1005][1005];
//int a[15],b[15],c[15];
int n,m,p;
int check(int x,int y){
	if(x<1||x>n||y<1||y>m||s[x][y]=='#'||vis[x][y])return 0;
	return 1;
}struct node{
	int x,y;
};
int dx[10]={0,0,1,-1};
int dy[10]={1,-1,0,0};
queue<node>q[15];
void bfs(int k){
	node no,ne;
	int h=q[k].size();
	while(h--){
		no=q[k].front();
		q[k].pop();
		for(int i=0;i<4;i++){
			ne.x=no.x+dx[i];
			ne.y=no.y+dy[i];
			if(check(ne.x,ne.y)){
				vis[ne.x][ne.y]=1;
				q[k].push(ne);
				b[k]++;
			}
		}
	}
}*/

ll ans1=0;
/*ap<int,int>m;
int dfs(int i,int n) {
    m[i]=1;
    int j=2;
    while(abs(i*j)<=n){
            ans1+=j;
            if(m[i*j]==0)
            dfs(i*j,n);
            ans1+=j;
            if(m[-i*j]==0)
            dfs(-i*j,n);
            j++;
    }
}*/
#define MAXN   100003
int spf[MAXN];
ll  calc[MAXN+1];
/*ll nCk(ll n,ll k,ll mod) {
    return ((((calc[n]%mod)*exponentMod(calc[k],mod-2,mod))%mod)*exponentMod(calc[n-k],mod-2,mod))%mod;
}*/
void sieve()
{
    spf[1] = 1;
    for (int i=2; i<MAXN; i++)
        spf[i] = i;
    for (int i=4; i<MAXN; i+=2)
        spf[i] = 2;

    for (int i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (int j=i*i; j<MAXN; j+=i)
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}
set<int>getFactorization(int x)
{
    set<int> ret;
    while (x != 1)
    {
        ret.insert(spf[x]);
        x = x / spf[x];
    }
    return ret;
}
bool prime[MAXN+1];
void sieve2()
{
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=MAXN; p++)
    {
        if (prime[p]==true)
        {
            for (int i=p*p; i<=MAXN; i += p)
                prime[i] = false;
        }
    }
}
int MEX(int a[],int n) {
    set<int>s;
    for(int i=0;i<n;i++) {
        s.insert(a[i]);
    }
    int c=0;
    for(auto i=s.begin();i!=s.end();i++) {
       if(*i==c) {
        c++;
       }
       else
        break;
    }
    return c;
}
int smallestDivisor(int n)
{
    if (n % 2 == 0)
        return 2;
    for (int i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }
    return n;
}

int setBitNumber(int n)
{
    if (n == 0)
        return 0;

    int msb = 0;
    n = n / 2;
    while (n != 0) {
        n = n / 2;
        msb++;
    }
    return msb;
}
int getMid(int s, int e)
{
	return s + (e - s) / 2;
}
int MaxUtil(int* st, int ss, int se, int l,
			int r, int node)
{
	if (l <= ss && r >= se)
		return st[node];
	if (se < l || ss > r)
		return -1;
	int mid = getMid(ss, se);

	return max(MaxUtil(st, ss, mid, l, r,
					2 * node + 1),
			MaxUtil(st, mid + 1, se, l,
					r, 2 * node + 2));
}
int constructSTUtil(int arr[], int ss, int se,
					int* st, int si)
{
	if (ss == se)
	{
		st[si] = arr[ss];
		return arr[ss];
	}
	int mid = getMid(ss, se);

	st[si] = max(constructSTUtil(arr, ss, mid, st,
								si * 2 + 1),
				constructSTUtil(arr, mid + 1, se,
								st, si * 2 + 2));

	return st[si];
}
int* constructST(int arr[], int n)
{
	int x = (int)(ceil(log2(n)));
	int max_size = 2 * (int)pow(2, x) - 1;
	int* st = new int[max_size];
	constructSTUtil(arr, 0, n - 1, st, 0);
	return st;
}
void updateValue(int arr[], int* st, int ss, int se,
				int index, int value, int node)
{
	if (ss == se)
	{
		arr[index] = value;
		st[node] = value;
	}
	else {
			int mid = getMid(ss, se);

			if (index >= ss && index <= mid)
				updateValue(arr, st, ss, mid, index,
							value, 2 * node + 1);
			else
				updateValue(arr, st, mid + 1, se,
							index, value, 2 * node + 2);

			st[node] = max(st[2 * node + 1],
					st[2 * node + 2]);
	}
	return;
}
int longest_subseq(int n, int k, int s[])
{
    vector<int> dp(n, 0);
    int max_length[300001] = {0};
    int* st = constructST(max_length, 300001);
    for(int i = 0; i < n; i++)
    {
        int curr = s[i];
        int lower = max(0, curr - k);
        int upper = min(300000, curr + k);
        int m1=MaxUtil(st,0,300000, lower, upper, 0);
        dp[i] = max(dp[i], m1 + 1);
        updateValue(max_length,st,0,300000,curr,max(dp[i],max_length[curr]),0);
    }
    int ans = 0;
    for(int i:dp) ans = max(i, ans);
    return ans;
}
int main()
{
    cena
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
     cout<<longest_subseq(n,k,a);
	return 0;
}













Measured memory_bytes: 11332