#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using ll = long long;
template <typename T>
std::ostream &operator<<(std::ostream &os, std::vector<T> vec) {
  if (!vec.empty()) {
    std::copy(vec.begin(), vec.end() - 1, std::ostream_iterator<T>(os, " "));
    os << vec.back();
  }
  return os;
}
template <typename T>
[[nodiscard]] auto read_n_items_to_vector(size_t n) -> std::vector<T> {
  auto ret = std::vector<T>(n, 0);
  for (auto &e : ret) {
    std::cin >> e;
  }
  return ret;
}
using namespace std;
using st = std::size_t;
using bo = uint8_t;
auto solve_wrapper() -> void {
  int n, k;
  cin >> n >> k;
  auto v = read_n_items_to_vector<int>(n);
  auto m = map<int, int>{};
  for (auto const &e : v) {
    auto iter = m.lower_bound(max(0, e - k));
    auto toIter = m.upper_bound(e + k);
    auto ma = m[e];
    while (iter != toIter) {
      auto [val, len] = *iter;
      ma = max(ma, len);
      ++iter;
    }
    m[e] = ma + 1;
  }
  auto ma = 0;
  for (auto const &[val, len] : m) {
    ma = max(len, ma);
  }
  std::cout << ma << "\n";
}
auto main() -> int {
  ll t = 1;
  while (t-- > 0) {
    solve_wrapper();
  }
  return 0;
}
