#include <bits/stdc++.h>
using namespace std;
int n, dat[2000004], K, n_ = 1;
void upd(int id, int x) {
  while (1) {
    dat[id] = max(dat[id], x);
    if (id == 0) break;
    id = (id - 1) / 2;
  }
}
int got(int l, int r, int id, int a, int b) {
  if (r < a || b < l) return 0;
  if (a <= l && r <= b) return dat[id];
  return max(got(l, (l + r) / 2, id * 2 + 1, a, b),
             got((l + r) / 2 + 1, r, id * 2 + 2, a, b));
}
int main() {
  cin >> n >> K;
  while (n_ < 3e5 + 1) n_ <<= 1;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    int cur = got(1, n_, 0, x - K, x + K) + 1;
    upd(x + n_ - 1, cur);
  }
  cout << got(1, n_, 0, -1114514, 1114514);
}
