#include <bits/stdc++.h>
using namespace std;
int seg[4 * 300005], ara[300005];
void update(int n, int s, int e, int indx, int val) {
  if (s == indx && e == indx) {
    seg[n] = val;
    return;
  }
  if (s > indx || e < indx) return;
  int mid = (s + e) / 2;
  update(n * 2, s, mid, indx, val);
  update(n * 2 + 1, mid + 1, e, indx, val);
  seg[n] = max(seg[n * 2], seg[n * 2 + 1]);
  return;
}
int query(int n, int s, int e, int l, int r) {
  if (s >= l && e <= r) return seg[n];
  if (s > r || e < l) return 0;
  int mid = (s + e) / 2;
  return max(query(n * 2, s, mid, l, r), query(n * 2 + 1, mid + 1, e, l, r));
}
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &ara[i]);
  int res = 0;
  for (int i = n; i >= 1; i--) {
    int x = query(1, 1, 300000, max(ara[i] - k, 1), min(ara[i] + k, 300000));
    update(1, 1, 300000, ara[i], x + 1);
    res = max(res, x + 1);
  }
  printf("%d\n", res);
  return 0;
}
