#include <bits/stdc++.h>
using namespace std;
const long long int INF = (1LL << 60);
const int INF_INT = 2147483647 - 1e6 - 1;
const long long int mod = 1000000007ll;
const int mod_int = 1000000007;
template <class Monoid>
struct SegmentTree {
  using Func = function<Monoid(Monoid, Monoid)>;
  const Func F;
  const Monoid UNITY;
  int SIZE_R;
  vector<Monoid> dat;
  SegmentTree(int n, const Func f, const Monoid &unity) : F(f), UNITY(unity) {
    init(n);
  }
  void init(int n) {
    SIZE_R = 1;
    while (SIZE_R < n) SIZE_R *= 2;
    dat.assign(SIZE_R * 2, UNITY);
  }
  void set(int a, const Monoid &v) { dat[a + SIZE_R] = v; }
  void build() {
    for (int k = SIZE_R - 1; k > 0; --k) dat[k] = F(dat[k * 2], dat[k * 2 + 1]);
  }
  void update(int a, const Monoid &v) {
    int k = a + SIZE_R;
    dat[k] = v;
    while (k >>= 1) dat[k] = F(dat[k * 2], dat[k * 2 + 1]);
  }
  Monoid query(int a, int b) {
    Monoid vleft = UNITY, vright = UNITY;
    for (int left = a + SIZE_R, right = b + SIZE_R; left < right;
         left >>= 1, right >>= 1) {
      if (left & 1) vleft = F(vleft, dat[left++]);
      if (right & 1) vright = F(dat[--right], vright);
    }
    return F(vleft, vright);
  }
  inline Monoid operator[](int a) { return dat[a + SIZE_R]; }
  void print() {
    for (int i = 0; i < SIZE_R; ++i) {
      cout << (*this)[i];
      if (i != SIZE_R - 1) cout << ",";
    }
    cout << endl;
  }
};
long long int N, K;
long long int A[300000];
long long int ans;
void solve() {
  auto func = [&](long long int a, long long int b) { return max(a, b); };
  SegmentTree<long long int> st(N + 2, func, 0);
  for (int i = 0; i < N; i++) {
    long long int left = max(0LL, A[i] - K);
    long long int right = min(N, A[i] + K);
    long long int cand = st.query(left, right + 1);
    st.update(A[i], cand + 1);
  }
  ans = st.query(1, N + 1);
}
int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> A[i];
  solve();
  cout << ans << endl;
  return 0;
}
