#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define reps(i, s, n) for(int i = (s); i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, s, n) for(int i = (n) - 1; i >= (s); i--)
#define INF ~(1 << 31)
#define INFL ~(1LL << 63)

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    vector<vector<int>> to(N);
    rep(i, N){
        cin >> A[i];
        rep(j, i){
            if(abs(A[i] - A[j]) <= K){
                to[j].push_back(i);
            }
        }
    }
    
    int ans = 0;
    rep(i, N-1){
        queue<pair<int, int>> que;
        que.push(make_pair(i, 1));
        while(!que.empty()){
            pair<int, int> tmp = que.front();
            que.pop();
            if(to[tmp.first].size() != 0){
                for(int a : to[tmp.first]){
                    que.push(make_pair(a, tmp.second + 1));
                }
            }else{
                ans = max(ans, tmp.second);
            }
        }
    }
    cout << ans << endl;
}