// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
struct node
{
    ll a;
};
ll n = N;
vector<node> t(2 * N);
node combine(node l, node r)
{
    node res;
    res.a = max(l.a, r.a);
    return res;
}
void update(int p, node value)
{
    for (t[p += n] = value; p >>= 1;)
        t[p] = combine(t[p << 1], t[p << 1 | 1]);
}
void build()
{
    for (ll i = n - 1; i > 0; --i)
        t[i] = combine(t[i << 1], t[i << 1 | 1]);
}
node query(ll l, ll r)
{
    node resl = {0}, resr = {0};
    for (l += n, r += n; l < r; l >>= 1, r >>= 1)
    {
        if (l & 1)
            resl = combine(resl, t[l++]);
        if (r & 1)
            resr = combine(t[--r], resr);
    }
    return combine(resl, resr);
}
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll &e : a)
        cin >> e;
    for (ll i = 0; i < n; i++)
    {
        ll l = max(0LL, a[i] - k);
        ll r = a[i] + k;
        ll x = query(l, r + 1).a + 1;
        update(a[i], {x});
    }
    cout << query(0, N).a;
}