#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.end()

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using ll = long long;
using ull = unsigned long long;
using namespace std;
using namespace atcoder;
// cout << fixed << setprecision(10）<<  << endl;

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

int main(){
    int n, k; cin >> n >> k;
    vector<int> a(n); rep(i,n) cin >> a[i];

    segtree<int, op, e> data(600600);
    rep(i,n){
        int num = a[i];
        num += 300300;
        int save = data.prod(num - k, num + k + 1);
        data.set(num, save + 1);
    }
    cout << data.all_prod() << endl;
    return 0;
}