#include<bits/stdc++.h>
#define	ll	long long
#define	pb	push_back
#define	sz(v)	(int)v.size()
#define	nl	"\n"
using namespace std; 
const int N = 300001; 
int ANS(int n,int mx, int mn, int k, vector<int> & ar) 
{ 
  
    vector<int> dp(n+1, 0); 
  
    int max_length[mx+1] = {0}; 
  
    for (int i = 0; i < n; i++)  
    {  
        int l = max(mn, ar[i] - k); 
        int r = min(mx, ar[i] + k); 
          
        for (int j = l; j < r + 1; j++) 
        { 
            dp[i] = max(dp[i], max_length[j] + 1); 
        }
        max_length[ar[i]] = max(dp[i], max_length[ar[i]]); 
    } 
  
    int ans = 0; 
  
    for(auto i : dp)
		ans = max(i, ans); 
    return ans; 
} 
  
int main() 
{ 
    int n, k;
    cin>>n>>k;
    vector<int>ar(n+1);
    int mx = INT_MIN, mn = INT_MAX;
    for(int i = 0; i<n; i++)
    {
    	cin>>ar[i];
    	mx = max(mx, ar[i]);
    	mn = min(mn, ar[i]);
	}
    cout<<ANS(n,mx, mn, k, ar)<<nl;
    return 0; 
    
}