#include <bits/stdc++.h>
using namespace std;
namespace IO {
template <typename T>
inline void read(T& x) {
  x = 0;
  bool f = 1;
  char ch;
  for (ch = getchar(); ch < '0' || '9' < ch; ch = getchar())
    if (ch == '-') f ^= 1;
  for (; '0' <= ch && ch <= '9'; ch = getchar())
    x = (x << 3) + (x << 1) + (ch ^ 48);
  x = f ? x : -x;
}
}  // namespace IO
const int MAXN = 1e6 + 10;
const int MAXVAL = 3e5;
int n, arr[MAXN], K, f[MAXN];
struct Segment_Tree {
  struct Node {
    int val;
  } t[MAXN << 2];
  void pushup(int k) { t[k].val = max(t[k << 1 | 1].val, t[k << 1].val); }
  void modify(int k, int l, int r, int pos, int val) {
    if (l == r) return t[k].val = val, void();
    if (pos <= ((l + r) >> 1))
      modify(k << 1, l, ((l + r) >> 1), pos, val);
    else
      modify(k << 1 | 1, ((l + r) >> 1) + 1, r, pos, val);
    pushup(k);
  }
  int query(int k, int l, int r, int ql, int qr) {
    if (ql <= l && r <= qr) return t[k].val;
    int res = 0;
    if (ql <= ((l + r) >> 1))
      res = max(res, query(k << 1, l, ((l + r) >> 1), ql, qr));
    if (qr > ((l + r) >> 1))
      res = max(res, query(k << 1 | 1, ((l + r) >> 1) + 1, r, ql, qr));
    return res;
  }
} sgt;
int main() {
  IO::read(n), IO::read(K);
  for (int i = (1), iend = (n); i <= iend; ++i) IO::read(arr[i]);
  for (int i = (1), iend = (n); i <= iend; ++i) {
    f[i] = sgt.query(1, 1, n, max(0, arr[i] - K), min(MAXVAL, arr[i] + K)) + 1;
    sgt.modify(1, 1, n, arr[i], f[i]);
  }
  printf("%d\n", sgt.query(1, 1, n, 0, MAXVAL));
  return 0;
}
