    //For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define int ll
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    ll tree[5000000];

    void build(int node,int l,int r)
    {
        if(l==r)
        {
            tree[node]=0;   //Change for min/sum
            return;
        }
        build(node*2,l,(l+r)/2);
        build(node*2+1,(l+r)/2+1,r);
        tree[node]=max(tree[node*2],tree[node*2+1]);    //Change for min/sum
    }

    void update(int node,int l,int r,int i,ll x)
    {
        if(i<l || r<i)
            return;
        if(l==r)
        {
            tree[node]=x;
            return;
        }
        update(node*2,l,(l+r)/2,i,x);
        update(node*2+1,(l+r)/2+1,r,i,x);
        tree[node]=max(tree[node*2],tree[node*2+1]);    //Change for min/sum
    }
    
    ll query(int node,int l,int r,int i,int j)
    {
        if(j<l || r<i)
            return 0;   //Change for min/sum
        if(i<=l && r<=j)
        {
            return tree[node];
        }
        ll q1=query(node*2,l,(l+r)/2,i,j);
        ll q2=query(node*2+1,(l+r)/2+1,r,i,j);
        return max(q1,q2);  //Change for min/sum
    }

    signed main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,i,j,x,k,z;
            cin>>n>>k;
            int ar[n+1];
            for(i=1;i<=n;++i)
            {
                cin>>ar[i];
            }
            build(1,0,300000);
            for(i=1;i<=n;++i)
            {
                x=query(1,0,300000,max(0,x-k),min(300000,x+k));
                update(1,0,300000,ar[i],x+1);
            }
            x=query(1,0,300000,0,300000);
            cout<<x<<endl;
        }
        return 0;
    }
