#include<bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
//const int mod=998244353;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
VL dx={1,0,-1,0};
VL dy={0,1,0,-1};
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
const int N=3e5+10;
struct  segtree
{
    int size;
    VL arr;
    void init(int n)
    {
        size=1;
        while(size<=n)
        {
            size*=2;
        }
        arr.assign(2*size,0LL);
    }
    void set(int pos,int val,int x,int lx,int rx)
    {
        if(rx-lx==1)
        {
            arr[x]=val;
            return;
        }
        ll m=(lx+rx)>>1;
        if(pos<m)
            set(pos,val,2*x+1,lx,m);
        else
            set(pos,val,2*x+2,m,rx);
        arr[x]=max(arr[2*x+1],arr[2*x+2]);
    }
    void set(int pos,int val)
    {
        set(pos,val,0,0,size);
    }
    int calc(int l,int r,int x,int lx,int rx)
    {
        if(lx>=r||rx<=l)return 0;
        if(l<=lx&&r>=rx)return arr[x];
        ll m=(lx+rx)>>1;
        return max(calc(l,r,2*x+1,lx,m),calc(l,r,2*x+2,m,rx));
    }
    int calc(int l,int r)
    {
        l=max(l,0);
        r=min(r,N);
        return calc(l,r,0,0,size);
    }
};

void solve()
{
    ll n,k;
    cin>>n>>k;
    segtree st;
    st.init(N+1);
    fr(i,0,n)
    {
        ll x;
        cin>>x;
        ll res=st.calc(x-k,x+k+1);
        //ll res=0;
        //cout<<"y0: "<<res<<endl;
        st.set(x,res+1);
    }
    cout<<st.calc(0,N)<<endl;
    return;
}
int main()
{
    IOS;
    ll t=1,pp;
    //cin>>t;
    pp=t;
    while(t--)
    {
        //cout<<"Case #"<<pp-t<<": ";
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
        * BE CAREFUL REGARDING THE DEFAULT VALUES IN segement trees etc
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 11396