#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>
#include <atcoder/all>

#define int long long

struct edge {
    int to;
    int cost;
};

using namespace std;
using namespace atcoder;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vb = vector<bool>;
using qi = queue<int>;
using P = pair<int, int>;
using graph = vector<vector<edge>>;
// using graph = vector<vector<int>>;
using mint = modint1000000007;


#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define delim(i, n) cout << (i == n-1 ? "\n" : " ")
#define print1(v) cout << fixed << setprecision(10) << v << "\n"
#define print2(v1, v2) cout << fixed << setprecision(10) << v1 << " " << v2 << "\n"
#define printvi(v, n) REP(iiii, n) { cout << v[iiii]; delim(iiii, n); }
#define printvii(v, h, w) REP(iiiii, h) { printvi(v[iiiii], w); }

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int inf = 1LL << 60;
// const int inf = 100000000;
const int mod = 1000000007;

const int maxn = 3e5;
int n, m, k;
vi a(maxn);

vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};

int op (int a, int b) {
    return max(a, b);
}
int e () {
    return -1;
}

signed main () {
	cin.tie(0);
   	ios::sync_with_stdio(false);

    cin >> n >> k;
    REP(i, n) {
        cin >> a[i];
        a[i]--;
    }
    
    vi tmp(maxn, 0);
    segtree<int, op, e> seg(tmp);
    REP(i, n) {
        int val = seg.prod(max(0LL, a[i]-k), min(maxn, a[i]+k+1));
        seg.set(a[i], val+1);
    }

    int ret = seg.prod(0, maxn);
    print1(ret);
}