#include <bits/stdc++.h>
using namespace std;
const int NMAX = 3e5 + 5;
int n, m, arb[4 * NMAX + 66], poz, val, start, finish, maxim, dp[NMAX], sol,
    v[NMAX], x;
void actualizare(int nod, int st, int dr) {
  int mij;
  if (st == dr) {
    arb[nod] = val;
    return;
  }
  mij = (st + dr) / 2;
  if (poz <= mij) {
    actualizare(2 * nod, st, mij);
  } else {
    actualizare(2 * nod + 1, mij + 1, dr);
  }
  arb[nod] = max(arb[2 * nod], arb[2 * nod + 1]);
}
void interogare(int nod, int st, int dr) {
  int mij;
  if (start <= st && dr <= finish) {
    if (maxim < arb[nod]) {
      maxim = arb[nod];
    }
    return;
  }
  mij = (st + dr) / 2;
  if (start <= mij) {
    interogare(2 * nod, st, mij);
  }
  if (mij < finish) {
    interogare(2 * nod + 1, mij + 1, dr);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    x++;
    start = max(1, x - m);
    finish = min(300001, x + m);
    maxim = 0;
    interogare(1, 1, n);
    dp[i] = 1 + maxim;
    sol = max(sol, dp[i]);
    poz = x;
    if (v[x] < dp[i]) {
      v[x] = dp[i];
      poz = x;
      val = v[x];
      actualizare(1, 1, 300001);
    }
  }
  cout << sol;
  return 0;
}
