#include<bits/stdc++.h>
#include<atcoder/segtree>

using namespace std;
using namespace atcoder;

#define int long long
#define rep(i,n) for(int i=0;i<n;i++)

int op(int a, int b) {return max(a, b);}
int e() {return -1;}

int N, K;
int A[300010];
segtree<int, op, e> seg(300010);

signed main()
{
    cin >> N >> K;
    rep(i, N)cin >> A[i];

    rep(i, N)
    {
        int now = seg.prod(max(0ll, A[i] - K), min(A[i] + K + 1, 300010ll)) + 1;
        now = max(now, 1ll);

        seg.set(A[i], now);
    }

    cout << seg.prod(0, 300010) << endl;

    return 0;
}