#include <bits/stdc++.h>
using namespace std;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false),
            cout << fixed << setprecision(12), 0);
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (auto &a : A) cin >> a;
  vector<pair<int, int>> B;
  for (int i = 0; i < N; i++) B.emplace_back(A[i], i);
  sort(begin(B), end(B));
  vector<vector<int>> prv(N);
  set<int> S;
  for (int i = 0; i < N; i++) {
    auto [val, idx] = B[i];
    auto it = S.lower_bound(idx);
    if (it != S.begin()) {
      --it;
      prv[idx].push_back(*it);
    }
    S.insert(B[i].second);
  }
  S.clear();
  for (int i = N - 1; i >= 0; i--) {
    auto [val, idx] = B[i];
    auto it = S.lower_bound(idx);
    if (it != S.begin()) {
      --it;
      prv[idx].push_back(*it);
    }
    S.insert(B[i].second);
  }
  vector<int> dp(N);
  for (int i = 0; i < N; i++) {
    dp[i] = 1;
    for (int p : prv[i]) {
      if (abs(A[i] - A[p]) <= K) {
        dp[i] = max(dp[i], dp[p] + 1);
      }
    }
  }
  cout << *max_element(begin(dp), end(dp)) << '\n';
  return 0;
}
