#include <bits/stdc++.h> 
using namespace std; 

void dfs(int node, vector<int> adj[], int dp[], int vis[]) 
{ 
    vis[node] = 1; 
  
    for (int i = 0; i < (int)adj[node].size(); i++) { 
  
        if (!vis[adj[node][i]]) 
            dfs(adj[node][i], adj, dp, vis); 
  
        dp[node] = max(dp[node], 1 + dp[adj[node][i]]); 
    } 
} 
  
void addEdge(vector<int> adj[], int u, int v) 
{ 
    adj[u].push_back(v); 
} 
  
int findLongestPath(vector<int> adj[], int n) 
{ 
    int dp[n + 1] = {};   
    int vis[n + 1] = {}; 
    for (int i = 1; i <= n; i++) { 
        if (!vis[i]) 
            dfs(i, adj, dp, vis); 
    } 
  
    int ans = 0; 
    for (int i = 1; i <= n; i++) { 
        ans = max(ans, dp[i]); 
    } 
    return ans; 
} 
 
 const int mxN = 2e6+1;
  
int main() 
{ 
    int n, k;
    cin >> n >> k;
    int arr[n];
    for(int i = 0 ; i < n ; i++){
        cin >> arr[i];
    }
    vector<int> adj[n+1]; 
    
    for(int i = 0 ; i < n ; i++){
        for(int j = i+1 ; j < n ; j++){
            if(abs(arr[i]-arr[j]) <= k && abs(arr[i]-arr[j]) >= 0){
                 addEdge(adj, i, j); 
            }
        }
    }    
  
    cout << findLongestPath(adj, n)+1; 
    return 0; 
} 