#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 3e5;
long long a[MAXN + 1] = {-1}, segMax[4 * (MAXN + 1)], segSum[4 * (MAXN + 1)];
void build(long long v, long long tl, long long tr) {
  if (tl == tr) {
    segMax[v] = a[tr];
    segSum[v] = a[tr];
    return;
  }
  long long tm = (tr + tl) / 2;
  build(2 * v + 1, tl, tm);
  build(2 * v + 2, tm + 1, tr);
  segMax[v] = max(segMax[2 * v + 1], segMax[2 * v + 2]);
  segSum[v] = segSum[2 * v + 1] + segSum[2 * v + 2];
}
long long query(long long v, long long tl, long long tr, long long l,
                long long r) {
  if (tl >= l && tr <= r) return segMax[v];
  if (tl > r || tr < l) return INT_MIN;
  long long tm = tl + (tr - tl) / 2;
  long long left = query(2 * v + 1, tl, tm, l, r);
  long long right = query(2 * v + 2, tm + 1, tr, l, r);
  return max(left, right);
}
long long sum(long long v, long long tl, long long tr, long long l,
              long long r) {
  if (l > r) return 0;
  if (l == tl && r == tr) {
    return segSum[v];
  }
  long long tm = (tl + tr) / 2;
  return sum(v * 2 + 1, tl, tm, l, min(r, tm)) +
         sum(v * 2 + 2, tm + 1, tr, max(l, tm + 1), r);
}
void update(long long v, long long tl, long long tr, long long pos,
            long long new_val) {
  if (tl == tr) {
    segMax[v] = new_val;
  } else {
    long long tm = (tl + tr) / 2;
    if (pos <= tm)
      update(v * 2 + 1, tl, tm, pos, new_val);
    else
      update(v * 2 + 2, tm + 1, tr, pos, new_val);
    segMax[v] = max(segMax[v * 2 + 1], segMax[v * 2 + 2]);
  }
}
signed main() {
  long long n, k;
  cin >> n >> k;
  long long b[n];
  for (long long i = 0; i < n; i++) cin >> b[i];
  long long max_ = *max_element(b, b + n);
  build(0, 0, max_);
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    long long l = max(0LL, b[i] - k);
    long long r = b[i] + k + 1;
    long long res = query(0, 0, max_, l, r);
    ans = max(ans, res + 1);
    update(0, 0, max_, b[i], res + 1);
  }
  cout << ans << endl;
}
