#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<int, ii>;
#define vt vector
#define pq priority_queue
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
const int MOD = 1e9 + 7;
const int INF = 2e9;
const int N = 3e5 + 5;

int n, k;
int a[N], dp[N][N];

int f(int idx, int last) {
    if(idx > n) return 0;
    int &sol = dp[idx][last];
    if(sol != -1) return sol;
    if(last == -1) {
        sol = max(f(idx + 1, last), 1 + f(idx + 1, a[idx]));
    } else {
        sol = f(idx + 1, last);
        if(abs(a[idx] - last) <= k) 
            sol = max(sol, 1 + f(idx + 1, a[idx]));
    }
    return sol;
}

void solve() {
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++) {
        cin >> n >> k;
        for(int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        memset(dp, -1, sizeof(dp));
        cout << f(1, -1) << "\n";
    }
}

int main() {
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
    
}