#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9;
const int N = 3e5 + 5;

struct node_t {
  int lo, hi, add_tag = 0, max_val = 0;
  
  void add(int tag) {
    add_tag += tag;
    max_val += tag;
  }
  
  void pushdown(node_t &lhs, node_t &rhs) {
    if (add_tag == 0) return;
    lhs.add(add_tag);
    rhs.add(add_tag);
    add_tag = 0;
  }

  void maintain(node_t &lhs, node_t &rhs) {
    max_val = max(lhs.max_val, rhs.max_val);
  }
};

struct seg_t {
  vector<node_t> seg;
  seg_t(int n) : seg(n + n) {
    int k = 1;
    while (k < n) k = k + k;
    int m = n + n - k, s = k - n;
    for (int i = 0; i < m; i++) seg[i + k] = {i, i + 1, 0};
    for (int i = m; i < n; i++) seg[i + s] = {i, i + 1, 0};
    for (int i = n - 1; i; i--) seg[i] = {seg[i + i].lo, seg[i + i + 1].hi, 0};
  }
  template <class Fn> void run(int l, int r, Fn &&fun, int i = 1) {
    if (r <= seg[i].lo || seg[i].hi <= l) return;
    if (l <= seg[i].lo && seg[i].hi <= r) return fun(seg[i]);
    seg[i].pushdown(seg[i + i], seg[i + i + 1]);
    run(l, r, fun, i + i);
    run(l, r, fun, i + i + 1);
    seg[i].maintain(seg[i + i], seg[i + i + 1]);
  }
  
  int query_max(int l, int r) {
    node_t res;
    res.max_val = -INF;
    run(l, r, [&](node_t &node) { res.maintain(res, node); });
    return res.max_val;
  }

  int query_sum(int l, int r) {
    node_t res;
    res.add_tag = 0;
    run(l, r, [&](node_t &node) { res.maintain(res, node); });
    return res.add_tag;
  }
  
  void add(int i, int val) { run(i, i + 1, [&](node_t &node) { node.add(val); }); }
  
  void update(int i, int val) { 
    int original = query_sum(i, i + 1);
    if (val > original) add(i, val - original);
  }
};

int main() {
  int n, k;
  cin >> n >> k;
  
  int ans = 0;
  seg_t seg(N);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    int new_ans = seg.query_max(max(0, a - k), a + k + 1) + 1;
    seg.update(a, new_ans);
    ans = max(ans, new_ans);

  }
  cout << ans;
}