#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
const int64_t INF = 1e18;
const int inf = 1e9;
const int64_t mod = 1e9 + 7;
bool print_space_enable = false;
void print() {
  cout << '\n';
  print_space_enable = false;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  if (print_space_enable) std::cout << " ";
  cout << fixed << setprecision(15) << head;
  print_space_enable = true;
  print(std::forward<Tail>(tail)...);
}
template <typename T>
void print(vector<T> v) {
  for (size_t i = 0; i < v.size(); i++) {
    if (i > 0) std::cout << " ";
    std::cout << v[i];
  }
  std::cout << '\n';
}
template <typename T>
class SegmentTree {
 private:
  int64_t n;
  vector<T> node;
  T ident;
  T f(T x, T y) { return max(x, y); }

 public:
  SegmentTree(vector<T> in, T identity_element)
      : n(in.size()), ident(identity_element) {
    node.resize(n * 2);
    for (int64_t i = 0; i < n; i++) node[n + i] = in[i];
    for (int64_t i = n - 1; i >= 1; i--)
      node[i] = f(node[i << 1 | 0], node[i << 1 | 1]);
  }
  void update(int64_t i, T value) {
    i += n;
    node[i] = value;
    while (i > 1) {
      i >>= 1;
      node[i] = f(node[i << 1 | 0], node[i << 1 | 1]);
    }
  }
  T query(int64_t l, int64_t r) {
    T ret = ident;
    l += n, r += n;
    while (l < r) {
      if (l & 1) ret = f(ret, node[l++]);
      if (r & 1) ret = f(ret, node[--r]);
      l >>= 1, r >>= 1;
    }
    return ret;
  }
};
void solve() {
  int64_t n, k;
  cin >> n >> k;
  vector<int64_t> a(n);
  for (int64_t i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  vector<int64_t> b(300002, 0);
  SegmentTree<int64_t> seg(b, 0);
  for (int64_t i = 0; i < n; i++) {
    int64_t l = max((int64_t)0, a[i] - k);
    int64_t r = min((int64_t)300000, a[i] + k);
    int64_t ma = seg.query(l, r + 1);
    seg.update(a[i], ma + 1);
  }
  print(seg.query(0, 300000 + 1));
}
int main() {
  solve();
  return 0;
}
