#include <bits/stdc++.h>
using namespace std;
int n, k, result, a;
int t[1300005];
void update(int idx, int l, int r, int aim, int val) {
  if (l == aim and aim == r) {
    t[idx] = val;
    return;
  }
  int mid = (l + r) >> 1;
  if (aim <= mid) {
    update(idx << 1, l, mid, aim, val);
  } else {
    update(idx << 1 | 1, mid + 1, r, aim, val);
  }
  t[idx] = max(t[idx << 1], t[idx << 1 | 1]);
  return;
}
int query(int idx, int l, int r, int aiml, int aimr) {
  if (aiml <= l and r <= aimr) {
    return t[idx];
  }
  int mid = (l + r) >> 1, ansl = 0, ansr = 0;
  if (aiml <= mid) {
    ansl = query(idx << 1, l, mid, aiml, aimr);
  }
  if (mid < aimr) {
    ansr = query(idx << 1 | 1, mid + 1, r, aiml, aimr);
  }
  return max(ansl, ansr);
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    result = query(1, 0, 300000, max(0, a - k), min(300000, a + k)) + 1;
    update(1, 0, 300000, a, result);
  }
  cout << result << endl;
  return 0;
}
