#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;
template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  for (ll j = 0; j < (ll)(v.size()); ++j) i >> v[j];
  return i;
}
template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) { return to_string(x).size(); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
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;
}
struct SegmentTree {
  vll seg;
  void initialize() {
    seg.resize((1 << 19) * 2);
    for (ll i = 0; i < (ll)((1 << 19) * 2); ++i) seg[i] = 0;
  }
  ll find(ll l, ll r) {
    l += (1 << 19);
    r += (1 << 19);
    ll res = -1;
    while (l < r) {
      if (l % 2 == 1) {
        chmax(res, seg[l]);
        ++l;
      }
      l /= 2;
      if (r % 2 == 1) {
        chmax(res, seg[r - 1]);
        --r;
      }
      r /= 2;
    }
    return res;
  }
  void update(ll i, ll x) {
    i += (1 << 19);
    seg[i] = x;
    while (true) {
      i /= 2;
      if (i == 0) break;
      seg[i] = max(seg[i * 2], seg[i * 2 + 1]);
    }
  }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  SegmentTree stree;
  stree.initialize();
  for (ll i = 0; i < (ll)(N); ++i) {
    ll a;
    cin >> a;
    a--;
    ll l = max(0ll, a - K);
    ll r = min(N - 1, a + K);
    if (l > N - 1) continue;
    ll val = stree.find(l, r + 1);
    stree.update(a, val + 1);
  }
  cout << (stree.find(0, N)) << "\n";
  return 0;
}
