#include<bits/stdc++.h>
using namespace std;

#define         ld                  long double
#define         lli                 long long int
#define         vi                  vector<int>
#define         vlli                vector<lli>
#define         vvi                 vector<vi >
#define         vvl                 vector<vlli >
#define         str                 string
#define         vs                  vector<str>
#define         vb                  vector<bool>
#define         mp                  make_pair
#define         pii                 pair<int, int>
#define         pll                 pair<lli, lli>
#define         vpii                vector<pii>
#define         vpll                vector<pll>
#define         pb                  push_back
#define         all(a)              a.begin(),a.end()
#define         rev(a)              reverse(all(a))
#define         min3(a, b, c)       min(a, min(b, c))
#define         max3(a, b, c)       max(a, max(b, c))
#define         ft                  first
#define         sd                  second

#define         loop(i, s, l, j)    for(int i = s; i < l; i += j)
#define         rloop(i, s, l, j)   for(int i = s; i >= l; i -= j)
#define         rep(i, n)           loop(i,0,n,1)
#define         rrep(i, n)          rloop(i,n-1,0,1) 

#define fastio() ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define mod 1000000007
#define inf 10000000
#define limit 300001

int tree[4*limit] = {}, A[4*limit] = {};
void update(int node, int start, int end, int idx, int val)
{
    if(start == end)
    {
        // Leaf node
        A[idx] = val;
        tree[node] = val;
    }
    else
    {
        int mid = (start + end) / 2;
        if(start <= idx and idx <= mid)
        {
            // If idx is in the left child, recurse on the left child
            update(2*node, start, mid, idx, val);
        }
        else
        {
            // if idx is in the right child, recurse on the right child
            update(2*node+1, mid+1, end, idx, val);
        }
        // Internal node will have the sum of both of its children
        tree[node] = max(tree[2*node], tree[2*node+1]);
    }
}
int query(int node, int start, int end, int l, int r)
{
    if(r < start or end < l)
    {
        return 0;
    }
    if(l <= start and end <= r)
    {
        // range represented by a node is completely inside the given range
        return tree[node];
    }
    // range represented by a node is partially inside and partially outside the given range
    int mid = (start + end) / 2;
    int p1 = query(2*node, start, mid, l, r);
    int p2 = query(2*node+1, mid+1, end, l, r);
    return max(p1, p2);
}

void solve(int test_case)
{
    int n;
    cin >> n;
    int k;
    cin >> k;

    vi a(n);
    rep(i,n)
        cin >> a[i];

    rep(i,n)
    {
        int l = max(0,a[i]-k);
        int r = min(limit-1,a[i]+k);
        int val = 1 + query(1,0,limit-1,l,r);
        update(1,0,limit-1,a[i],val);   
    }
    cout << tree[1] << '\n';
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    fastio();
    int q = 1;
    //cin >> q;
    rep(i,q)
        solve(i+1);
}


Measured memory_bytes: 9744