#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
const ll MOD = 1000000007;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
class SegmentTree {
 private:
  ll len;
  vl seg;

 public:
  SegmentTree(ll n) {
    len = n;
    seg.resize(2 * n, 0);
  }
  void add(ll ind, ll x) {
    ind += len;
    seg[ind] += x;
    while (true) {
      ind /= 2;
      if (ind == 0) break;
      seg[ind] = max(seg[2 * ind], seg[2 * ind + 1]);
    }
  }
  void update(ll ind, ll x) {
    ind += len;
    seg[ind] = x;
    while (true) {
      ind /= 2;
      if (ind == 0) break;
      seg[ind] = max(seg[2 * ind], seg[2 * ind + 1]);
    }
  }
  ll get_max(ll l, ll r) {
    ll ans = 0;
    l += len;
    r += len;
    while (l < r) {
      if (l % 2 == 1) {
        chmax(ans, seg[l]);
        l++;
      }
      l /= 2;
      if (r % 2 == 1) {
        chmax(ans, seg[r - 1]);
        --r;
      }
      r /= 2;
    }
    return ans;
  }
};
signed main() {
  ll n, k;
  cin >> n >> k;
  vl a(n);
  SegmentTree seg(n + 1);
  for (long long i = 0; i < (long long)(n); i++) {
    ll x;
    cin >> x;
    a[i] = x;
  }
  for (long long i = 0; i < (long long)(n); i++) {
    ll l = max((ll)1, a[i] - k);
    ll r = min(n, a[i] + k);
    seg.update(a[i], seg.get_max(l, r + 1) + 1);
  }
  cout << seg.get_max(1, n + 1) << endl;
  return 0;
}
