#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
const long long SEG_MAX = (1 << 20);
long long seg[SEG_MAX * 2] = {0};
void add(long long a, long long b, long long x, long long k = 0,
         long long l = 0, long long r = SEG_MAX - 1) {
  if (a <= l && r <= b) {
    seg[k] = max(seg[k], x);
  } else {
    long long l0 = l;
    long long r0 = l + (r - l) / 2;
    long long l1 = r0 + 1;
    long long r1 = r;
    if (a <= r0) {
      long long kk = 2 * k + 1;
      add(a, b, x, kk, l0, r0);
    }
    if (l1 <= b) {
      long long kk = 2 * k + 2;
      add(a, b, x, kk, l1, r1);
    }
  }
}
long long get(long long index) {
  long long sum = 0;
  long long k = SEG_MAX - 1 + index;
  while (true) {
    sum = max(sum, seg[k]);
    if (k == 0) break;
    k = (k - 1) / 2;
  }
  return sum;
}
signed main() {
  long long N, K;
  cin >> N >> K;
  for (long long(n) = 0; (n) < (N); (n)++) {
    long long a;
    cin >> a;
    long long l = max(0LL, a - K);
    long long r = a + K;
    add(l, r, get(a) + 1);
  }
  long long ans = 0;
  for (long long i = 1; i <= N; i++) {
    ans = max(get(i), ans);
  }
  cout << ans << endl;
}
