#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>
#include <atcoder/all>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 998244353;

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

int e() {
    return 0;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, k;
    cin >> n >> k;

    int a[n];
    for(int i=0;i<n;++i) {
        cin >> a[i];
    }

    atcoder::segtree<int, op, e> seg(300001);
    seg.set(a[0], 1);
    for(int i=1;i<n;++i) {
        int max_prev = seg.prod(max(0, a[i]-k), min(300000, a[i]+k+1));
        seg.set(a[i], max_prev + 1);
    }

    cout << seg.all_prod() << endl;
}