// *
// *
// *  Created By :hozaifa wahid
// * "mai maut ko takia aur kafan ko chadar banakar sota hu" 
// *------------------------------------
// *  OS : Ubuntu 16.04
// *  Language : CPP14
// *  Editor : Sublime Text 3
// *  C++ compiler : g++
// *https://www.geeksforgeeks.org/space-and-time-efficient-binomial-coefficient/
// *https://www.geeksforgeeks.org/binomial-coefficient-dp-9/
//https://www.geeksforgeeks.org/compute-ncr-p-set-2-lucas-theorem/
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define fr first
#define sc second
#define eps 1e-9
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define sni(x) scanf("%d",&x)
#define snl(x) scanf("%lld", &x)
#define snc(x) scanf("%c", &c);
#define rep(n) for(int i = 0 ; i < n ;i ++)
#define repc(i, n) for(int i = 0 ; i < n ; i ++)
#define FOR(i, x, y) for(int i = x ; i < y ; i ++)
#define DEC(i, x, y) for(int i = x ; i >= y ; i --)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b,c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a+n
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
ll a[300005];
ll vis[300005];
ll n,k;

ll go()
{
    vector<ll> dp(n, 0); 
  
    
    ll max_length[n] = {0}; 
  
    for (ll i = 0; i < n; i++)  
    { 
  
       
        ll curr = a[i]; 
        ll mini=*min_element(a,a+n);
        ll maxi=*max_element(a,a+n);
        
        ll lower = max(mini, curr - k); 
          
        
        int upper = min(maxi, curr + k); 
          
        
        for (ll j = lower; j < upper + 1; j++) 
        { 
            dp[i] = max(dp[i], max_length[j] + 1); 
        } 
        
        max_length[curr] = max(dp[i], max_length[curr]); 
    } 
  
    ll ans = 0; 
  
    for(ll i:dp) ans = max(i, ans); 
  
    
    return ans; 
}


void solve()
{
//comb(2001,2001);
std::ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
ll t;
//cin>>t;
//buildPrefix();
 t=1;
while(t--)
{
  cin>>n>>k;
  FOR(i,0,n)
  cin>>a[i];
  ll res=go();
  cout<<res;
  
}
}
 
 
 
int main(){
    std::ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    
    solve();
    
}
 
 
 
 
 
 
 
 
 
 