#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<chrono>
#include<typeinfo>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds; 
#define lli long long int
#define fr(i,a,b) for(lli i=a;i<b;i++)
#define bfr(i,a,b) for(lli i=a;i>=b;i--)
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
#define tc int t;cin>>t;while(t--)
#define mod 1000000007LL
#define mod2 998244353LL
#define all(vec) vec.begin(),vec.end()  
#define ld long double
#define pb push_back
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update> 
lli pmod(lli x,lli y){lli res=1;while(y>0){if(y&1)res = ((res%mod)*(x%mod))%mod;y>>=1;x= ((x%mod)*(x%mod))%mod;}return res;} 
lli power(lli x,lli y){lli res=1;while(y>0){if(y&1)res=res*x;y>>=1;x=x*x;}return res;}




int main()
{
  
         

    fio
    
    lli n,k;
    cin>>n>>k;

     lli a[n];
     fr(i,0,n)cin>>a[i];

     lli len = sqrt(300100)+1;
     //cout<<len<<'\n';

     lli sd[len]={0},maxi=-1e18,p[300100]={0};

     fr(i,0,n)
     {

         lli l=max(a[i]-k,0LL),r=a[i];
         maxi=-1e18;
         //cout<<l<<" "<<r<<'\n';

         for (int j=l; j<=r; )
        if (j % len == 0 && j + len - 1 <= r) {
            maxi= max(p[j/len],maxi);
            j+= len;
        }
        else {
            maxi=max(p[j],maxi);
            j++;
        }

        r=min(a[i]+k,300100LL),l=a[i];

         for (int j=l; j<=r; )
        if (j % len == 0 && j + len - 1 <= r) {
            maxi= max(p[j/len],maxi);
            j+= len;
        }
        else {
            maxi=max(p[j],maxi);
            j++;
        }
        //cout<<maxi<<'\n';

        p[a[i]]=maxi+1;
        sd[a[i]/len]=max(maxi,sd[a[i]/len]);




     }


    

     fr(i,0,300100)maxi=max(p[i],maxi);
     cout<<maxi;


   






  
     

    


     

     


    
      




 

return 0;}