#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 3;
int n, k;
int t[N * 4];
void upd(int pos, int val, int v = 1, int tl = 1, int tr = N - 1) {
  if (tl == tr) {
    t[v] = max(val, t[v]);
  } else {
    int tm = (tl + tr) >> 1;
    if (pos <= tm)
      upd(pos, val, v << 1, tl, tm);
    else
      upd(pos, val, v << 1 | 1, tm + 1, tr);
    t[v] = max(t[v << 1], t[v << 1 | 1]);
  }
}
int get(int l, int r, int v = 1, int tl = 1, int tr = N - 1) {
  if (tl > r || l > tr || l < 1 || r >= N) return 0;
  if (l <= tl && tr <= r) return t[v];
  int tm = (tl + tr) >> 1;
  return max(get(l, r, v << 1, tl, tm), get(l, r, v << 1 | 1, tm + 1, tr));
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    int cur = max(get(x - k, x), get(x, x + k));
    upd(x, cur + 1);
  }
  cout << t[1] << endl;
}
