#include <iostream>
#include <bitset>
#include <algorithm>        // sort()
#include <vector>           // for vectors
#include <map>              // for ordered map
#include <unordered_map>
#include <list>             // for list
#include <iomanip>          // for setprecision()
#include <cmath>            // for pow(), sqrt(), log(), log10(), ....
#include <cstring>          // for memset()
#include <unordered_set>    // for unordered_set
#include <climits>          // for INT_MAX & INT_MIN
#include <set>     
using namespace std; 

int main() 
{ 
  ll n, k, a, b, x, ans=NINF, ma=NINF;
        cin >> n >> k;
        ll s[n];
        for(ll i=0; i<n; i++) {
            cin >> s[i];
        }
	vector<int> dp(n, 0); 

	int max_length[300001] = {0}; 

	for (int i = 0; i < n; i++) 
	{
		int curr = s[i]; 
		
		int lower = max(0, curr - k); 
		
		int upper = min(300000, curr + k); 
		
		for (int j = lower; j < upper + 1; j++) 
		{ 
			dp[i] = max(dp[i], max_length[j] + 1); 
		} 
		max_length[curr] = max(dp[i], max_length[curr]); 
	} 

	int ans = 0; 

	for(int i:dp) {
      ans = max(i, ans); 
    }
  cout << ans << endl;
	return 0; 
} 

// This code is contributed by Mohit Kumar 
