#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

// Range Max Quely
int op(int a, int b) {
    return max(a, b);
}

int e() {
    return (int)(0);
}

int main(void)
{
    IOS
    constexpr int N = 300000;
    int n, k;
    cin >> n >> k;
    atcoder::segtree<int,op,e> seg(N);
    int ans = 0;
    REP(_,n) {
        int a; cin >> a;
        a--;
        int p = seg.prod(max(0,a-k),min(n,a+k+1))+1;
        seg.set(a,p);
        ans = max(ans,p);
        //cerr << ans << endl;
    }
    cout << ans << '\n';

    return 0;
}