#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vll vector<long long>
#define pll pair<long long, long long>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1e18
 

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;

// change N 
const ll N = 1e6 + 6;
ll lo[4 * N + 1], hi[4 * N + 1], delta[4 * N + 1], mini[4 * N + 1];

// change update and rmq according to question

void buildSeg(ll node, ll l, ll r)
{
    lo[node] = l;
    hi[node] = r;
    if (l == r)
    {
        return;
    }
    ll mid = l + (r - l) / 2;
    buildSeg(2 * node + 1, l, mid);
    buildSeg(2 * node + 2, mid + 1, r);
}

void prop(ll i)
{
    delta[2 * i + 1] += delta[i];
    delta[2 * i + 2] += delta[i];
    delta[i] = 0;
}

void update(ll i)
{
    mini[i] = max(mini[2 * i + 1] + delta[2 * i + 1], mini[2 * i + 2] + delta[2 * i + 2]);
}

void increment(ll i, ll l, ll r, ll val)
{
    if (r < lo[i] || l > hi[i])
    {
        return;
    }
    if (l <= lo[i] && r >= hi[i])
    {
        delta[i] = val;
        return;
    }
    prop(i);

    increment(2 * i + 1, l, r, val);
    increment(2 * i + 2, l, r, val);
    update(i);
}

ll rmq(ll i, ll l, ll r)
{
    if (r < lo[i] || l > hi[i])
    {
        return -1;
    }
    if (l <= lo[i] && r >= hi[i])
    {
        return mini[i] + delta[i];
    }
    prop(i);
    ll lefmin = rmq(2 * i + 1, l, r);
    ll rigmin = rmq(2 * i + 2, l, r);
    update(i);
    return max(lefmin, rigmin);
}

void solve()
{
    ll n,k;
    cin>>n>>k;
    ll i,j;
    ll a[n+1];
    buildSeg(1,1,N+5);
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    ll dp[n+1];
    clr(dp);
    dp[0]=0;
    for(i=1;i<=300003;i++)
    {
        increment(1,i,i,0ll);
    }
    for(i=1;i<=n;i++)
    {
        // dp[i] = max(a[i]-k to a[i]+k)
        ll l = max(0ll,a[i]-k);
        ll r = min(300003ll,a[i]+k);
        ll no = rmq(1,l,r);
        // cout<<a[i]<<" "<<l<<" "<<r<<" "<<no<<"\n";
        dp[i]=no+1;
        ll no2 = rmq(1,a[i],a[i]);
        if(dp[i]>no2){
        increment(1,a[i],a[i],dp[i]);
        }
        dp[i]=max(dp[i],dp[i-1]);
    }
    cout<<dp[n]<<"\n";
}


int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}