#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;
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;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

struct item
{
    ll sum;
};
struct segtree{
    int size;
    vector<item> values;

    item NEUTRAL_ELEMENT={0};

    item merge(item a,item b)
    {
        return{
            max(a.sum,b.sum)
        };
    }

    item single(int v)
    {
        if(v>=0)
            return {v};
        else
            return {0};
    }
    void init(int n)
    {
        size=1;
        while(size<=n)size*=2;
        values.resize(2*size);
    }
    void build(VL &arr,int x,int lx,int rx)//build
    {
        if(rx-lx==1)
        {
            if(lx<arr.size())
            {
                values[x]=single(arr[lx]);
            }
            else
                values[x]=NEUTRAL_ELEMENT;
            return;
        }
        int m=(lx+rx)>>1;
        build(arr,2*x+1,lx,m);
        build(arr,2*x+2,m,rx);
        values[x]=merge(values[2*x+1],values[2*x+2]);
    }
    void build(VL & arr)//build
    {
        build(arr,0,0,size);
    }
    void set(int i,int v,int x,int lx,int rx)
    {
        if(rx-lx==1)
        {
            values[x]=single(v);
            return;
        }
        int m=(lx+rx)>>1;
        if(i<m)
        {
            set(i,v,2*x+1,lx,m);
        }
        else
        {
            set(i,v,2*x+2,m,rx);
        }
        values[x]=merge(values[2*x+1],values[2*x+2]);
    }

    void set(int i ,int v)
    {
        set(i,v,0,0,size);
    }
    item calc(int l,int r,int x,int lx,int rx)
    {
        if(lx>=r||l>=rx)return NEUTRAL_ELEMENT;
        if(lx>=l&&rx<=r)return values[x];
        int m=(lx+rx)>>1;
        return merge(calc(l,r,2*x+1,lx,m),calc(l,r,2*x+2,m,rx));
    }
    item calc(int l,int r)
    {
        return calc(l,r,0,0,size);   
    }

    int find(int k,int l,int x,int lx,int rx)
    {
        if(values[x].sum<k)
            return (ll)-1;
        if(rx<=l) return -1;
        if(rx-lx==1)
        {
            // if(values[x].sum<k)
            //     return (ll)-1;
            // else
                return lx;
        }
        int m=(lx+rx)>>1;
        
        int p=find(k,l,2*x+1,lx,m);
        if(p==-1)
        {
            p=find(k,l,2*x+2,m,rx);
        }
        return p;
    }
    int find(int k,int l)
    {
        return find(k,l,0,0,size);
    }
};
const int N=3e5+10;
void solve()
{
    ll n,k;
    cin>>n>>k;
    //cout<<"ook\n";
    segtree st;
    st.init(N);
    VL arr(N);
    //cout<<"ok\n";
    // fr(i,0,n)
    // {
    //     cin>>arr[i];
    // }
    st.build(arr);
    //cout<<"ok\n";
    //cout<<st.calc(0,n).seg<<endl;
    fr(j,0,n)
    {
        ll x;
        cin>>x;
        ll l=max(x-k,0LL);
        ll r=min(x+k,(ll)N);
        ll res=st.calc(l,r).sum;
        st.set(x,res+1);
        // ll t=1;
        // cin>>t;
        // //cout<<"ok\n";
        // if(t==1)
        // {
        //     ll i,v=-1;
        //     cin>>i>>v;
        //     st.set(i,v);
        //     //cout<<st.calc(0,n).seg<<endl;
        // }
        // else
        // {
        //     ll l,r,k;
        //     cin>>k>>l;
        //     //cout<<st.sum(l,r)<<endl;
        //     // ll low=1,high=n;
        //     // ll ans=-1;
        //     // while(low<=high)
        //     // {
        //     //     ll mid=(low+high)>>1;
        //     //     item fuck=st.calc(0,mid);
        //     //     if(fuck.sum>=k+1)
        //     //     {
        //     //         ans=mid;
        //     //         high=mid-1;
        //     //     }
        //     //     else{
        //     //         low=mid+1;
        //     //     }

        //     // }
        //     cout<<st.find(k,l)<<endl;
        // }
    }
    cout<<st.calc(0,N).sum+1<<endl;
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        //cout<<"Case #"<<pp-t<<":\n";
        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
*/
/*
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