#include <bits/stdc++.h>
using namespace std;
const int64_t MAXN = (int64_t)3e5 + 2;
const int64_t INF = numeric_limits<int64_t>::max() >> 1;
const int64_t MOD = (int64_t)1000000007;
int64_t it[MAXN];
void update(int64_t id, int64_t l, int64_t r, int64_t p, int64_t val) {
  if (l > p || r < p || l > r) return;
  if (l == p && r == p) {
    if (it[id] < val) it[id] = val;
    return;
  }
  int64_t mid = (l + r) / 2;
  update(id << 1, l, mid, p, val);
  update(id << 1 | 1, mid + 1, r, p, val);
  it[id] = max(it[id << 1], it[id << 1 | 1]);
}
int64_t get(int64_t id, int64_t l, int64_t r, int64_t L, int64_t R) {
  if (l > r || l > R || r < L) return -INF;
  if (L <= l && r <= R) return it[id];
  int64_t mid = (l + r) / 2;
  return max(get(id << 1, l, mid, L, R), get(id << 1 | 1, mid + 1, r, L, R));
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  freopen("FDT.txt", "r", stdin);
  fill(it, it + MAXN, -INF);
  int64_t n, k;
  cin >> n >> k;
  vector<int64_t> a(n + 1);
  for (int64_t i = 1; i <= n; i++) cin >> a[i];
  for (int64_t i = n; i >= 1; i--) {
    int64_t lf = a[i] - k;
    if (lf < 0) lf = 0;
    int64_t rt = a[i] + k;
    if (rt > n) rt = n;
    int64_t d = get(1, 1, n, lf, rt);
    if (d < 0) d = 0;
    d++;
    update(1, 1, n, a[i], d);
  }
  cout << get(1, 1, n, 0, n);
}
