#include <bits/stdc++.h>
using namespace std;
int a[300005];
int t[5 * 300005];
int get(int lo, int hi, int idx, int qs, int qe) {
  if (qe < lo || hi < qs) return 0;
  if (qs <= lo && hi <= qe) return t[idx];
  int mid = (lo + hi) >> 1;
  int right = (idx + 1) << 1;
  return max(get(lo, mid, right - 1, qs, qe), get(mid + 1, hi, right, qs, qe));
}
void update(int lo, int hi, int idx, int ui, int val) {
  if (ui < lo || hi < ui) return;
  if (lo == hi) {
    t[idx] = val;
    return;
  }
  int mid = (lo + hi) >> 1;
  int right = (idx + 1) << 1;
  update(lo, mid, right - 1, ui, val);
  update(mid + 1, hi, right, ui, val);
  t[idx] = max(t[right - 1], t[right]);
}
int main() {
  int k, m, n;
  scanf("%d%d", &n, &k);
  m = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    m = max(m, a[i]);
  }
  m++;
  memset(t, 0, sizeof(int) * (5 * m));
  for (int i = n - 1; i >= 0; i--) {
    int lo = max(0, a[i] - k);
    int hi = min(m - 1, a[i] + k);
    int c = get(0, m - 1, 0, lo, hi);
    update(0, m - 1, 0, a[i], c + 1);
  }
  printf("%d\n", get(0, m - 1, 0, 0, m - 1));
}
