#include <bits/stdc++.h>
using namespace std;
int n, k;
int tree[1200003];
void update(int pos, int kir, int kan, int idx, int val) {
  if (idx == kir && kan == idx)
    tree[pos] = val;
  else if (idx < kir || idx > kan)
    return;
  else {
    int mid = (kir + kan) / 2;
    update(pos * 2, kir, mid, idx, val);
    update(pos * 2 + 1, mid + 1, kan, idx, val);
    tree[pos] = max(tree[pos * 2], tree[pos * 2 + 1]);
  }
}
int query(int pos, int kir, int kan, int qkir, int qkan) {
  if (qkan < kir || kan < qkir)
    return 0;
  else if (qkir <= kir && kan <= qkan)
    return tree[pos];
  int mid = (kir + kan) / 2;
  int a = query(pos * 2, kir, mid, qkir, qkan);
  int b = query(pos * 2 + 1, mid + 1, kan, qkir, qkan);
  return max(a, b);
}
int main() {
  scanf("%d %d", &n, &k);
  while (n--) {
    int x;
    scanf("%d", &x);
    int num = query(1, 1, 300000, max(1, x - k), min(300000, x + k));
    update(1, 1, 300000, x, num + 1);
  }
  printf("%d\n", tree[1]);
}
