//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <bitset>
#include <assert.h>
using namespace std;

typedef long long ll;
#define free  freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
#define Fast  ios::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define F first
#define S second
const int mod = 998244353;
const int N = 3e5+ 5;
ll mx = 0;

pair <ll, ll> p;
//stack <int> st1;
string s, s1;
char o;
bool mark, h;
//vector <ll> vt[N], vm, vs;
ll a[N], b, c, d, dp, dis, tree[6*N];
bool vowel(char che){if (che == 'A' || che == 'E' || che == 'I' || che == 'O' || che == 'U' || che == 'Y'){return true;} else{return false;}}
ll pw(ll a, ll b){ll ans = 1;while (b){if (b%2 == 1){ans *= a;ans %= mod;}b /= 2;a*= a;}return ans;}

void build(ll node, ll st, ll ed)
{
    if (st == ed){
        if (mark[st])
            tree[node] = 1;
    }
    else {
        ll mid = (st+ed) / 2;
        build (2*node, st, mid);
        build (2*node+1, mid+1, ed);
        tree[node] = max(tree[2*node], tree[(2*node)+1]);
    }
}

void update (ll node, ll st, ll ed, ll id, ll val)
{
    if (st == ed)
        tree[node] = val;
    else {
        ll mid = (st+ed)/2;
        if (id <= mid)
            update (2*node, st, mid, id, val);
        else
            update ((2*node)+1, mid+1, ed, id, val);

        tree[node] = max(tree[2*node], tree[(2*node)+1]);
    }
}

ll query (ll node, ll st, ll ed, ll l, ll r)
{
    if (r < st || l > ed)
        return 0;
    if (l <= st && ed <= r)
        return tree[node];
    ll mid = (st+ed)/2;
    ll q1 = query(2*node, st, mid, l, r);
    ll q2 = query((2*node)+1,mid+1, ed, l, r);
    return max(q1, q2);
}
int main()
{
    Fast
    ll t = 0, n, m = 0, k = 0, f = 0, sum = 0, ans = 0;
    cin >> n >> k;
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    build(1, 0, N)
    for (int i = 0; i < n; i++){
        ll l = max(ll(0), a[i]-k);
        ll r = min(ll(N), a[i]+k);
        ans = query(1, 0, N, l, r)+1;
        update (1, 0, N-1, a[i], ans);
    }
    cout << tree[1] << endl;
}
