//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007ll //998244353ll
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=300005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
int ar[N], st[4*N],n;
void build(int v, int l, int r)
{
    if(l==r)
    {
        st[v]=ar[l];
        return;
    }
    int m=(l+r)/2;
    build(v*2, l, m);
    build((v*2)+1, m+1, r);
    st[v]=max(st[v*2], st[(v*2)+1]);
    //cout<<l<<" "<<r<<" "<<t[v].o<<" "<<t[v].c<<" "<<t[v].ans<<"\n";
}
void update(int v, int l, int r, int pos)
{
    if(l==r)
    {
        st[v]=ar[l];
        return;
    }
    int m=(l+r)/2;
    if(pos<=m)
    update(v*2, l, m, pos);
    else
    update((v*2)+1, m+1, r, pos);
    st[v]=max(st[v*2], st[(v*2)+1]);
    //cout<<l<<" "<<r<<" "<<t[v].o<<" "<<t[v].c<<" "<<t[v].ans<<"\n";
}
int query(int v, int tl, int tr, int l, int r)
{
    if(l>r)
    return 0;
    if(tl==l&&tr==r)
    return st[v];
    int tm=(tl+tr)/2;
    return max(query((2*v), tl, tm, l, min(tm, r)), query((2*v)+1, tm+1, tr, max(tm+1, l), r));
}
int32_t main()
{
    IOS;
    int k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]++;
    }
    for(int i=1;i<N;i++)
    ar[i]=0;
    build(1, 1, N-1);
    int ans[n];
    for(int i=0;i<n;i++)
    {
        int lb=max(a[i]-k, 1ll);
        int ub=min(a[i]+k, N-1);
        ans[i]=1+query(1, 1, N-1, lb, ub);
        if(i)
        ans[i]=max(ans[i], ans[i-1]);
        ar[a[i]]=max(ar[a[i]], ans[i]);
        update(1, 1, N-1, a[i]);
    }
    cout<<ans[n-1];
}