/*
 © 2020-09-26 07:00:12 Franco1010 All Rights Reserved
*/

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <atcoder/all>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
using namespace atcoder;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
#define deb(x) cout << #x": " << (x) << endl;
lli op(lli a, lli b){
  return max(a, b);
}
lli e(){
  return 0;
}
int main(){ _
  lli n, k; cin >> n >> k;
  vector<lli> v(n);
  segtree<lli, op, e> st(3e5 + 5);
  lli res = 0;
  fore(i, 0, n){
    cin >> v[i];
    lli foo = st.prod(max(v[i] - k, 0ll), min(v[i] + k + 1ll, n)) + 1ll;
    res = max(res, foo);
    st.set(v[i], foo);
  }
  cout << res << ENDL;
  return 0;
}

