#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
int op(int a, int b){
    return max(a, b);
}
int e(){ 
    return 0;
}
int main(){
    int n, k;
    cin >> n >> k;
    vector<int>v(n + 3);
    int mx = 0;
    for(int i = 1; i <= n; i++){
        cin >> v[i];
        mx = max(mx, v[i]);
    }
    segtree<int, op, e> seg(mx + 5);
    vector<int>dp(n + 3, 0);
    for(int i = 1; i <= n; i++){
        int x = max(v[i] - k, 0);
        int y = min(v[i] + k, mx);
        int p = seg.prod(x, v[i] + 1);
        int q = seg.prod(v[i], y + 1);
        int r = seg.prod(v[i], v[i] + 1);
        dp[i] = max(dp[p], dp[q]) + 1;
        dp[i] = max(dp[i], dp[r] + 1);
        seg.set(v[i], i);
    }
    cout << dp[n];
    return 0;
}