#include <bits/stdc++.h>
using namespace std;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= (1ll << 32);
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % (1ll << 32);
    a = a * a % (1ll << 32);
  }
  return res;
}
long long Inv(long long b) { return powmod(b, (long long)(1ll << 32) - 2); }
const int N = 300005;
const double eps = 1e-9;
const long long inf = 1e18;
int a[N];
int seg[N << 4];
void push_up(int p) { seg[p] = max(seg[p << 1], seg[p << 1 | 1]); }
void update(int p, int l, int r, int L, int R, int val) {
  if (L > r || R < l) return;
  if (L <= l && R >= r)
    seg[p] = max(seg[p], val);
  else {
    int mid = (l + r) >> 1;
    update(p << 1, l, mid, L, R, val);
    update(p << 1 | 1, mid + 1, r, L, R, val);
    push_up(p);
  }
}
int query(int p, int l, int r, int L, int R) {
  if (L > r || R < l) return 0;
  if (L <= l && R >= r) return seg[p];
  int mid = (l + r) >> 1;
  return max(query(p << 1, l, mid, L, R), query(p << 1 | 1, mid + 1, r, L, R));
}
int main() {
  int n, k, x, nn = 600000;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &x);
    int tmp = query(1, 1, nn, max(0, x - k), x + k);
    update(1, 1, nn, x, x, tmp + 1);
  }
  printf("%d\n", seg[1]);
  return 0;
}
