#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int val[N << 1];
int a[N];
void pushUp(int u) { val[u] = max(val[u << 1], val[u << 1 | 1]); }
void update(int u, int l, int r, int x, int d) {
  if (l == r) {
    val[u] += d;
    return;
  }
  int mid = l + r >> 1;
  if (x <= mid)
    update(u << 1, l, mid, x, d);
  else
    update(u << 1 | 1, mid + 1, r, x, d);
  pushUp(u);
}
int query(int u, int l, int r, int x, int y) {
  if (x <= l && r <= y) {
    return val[u];
  }
  int res = 0;
  int mid = l + r >> 1;
  if (x <= mid) res = max(res, query(u << 1, l, mid, x, y));
  if (y > mid) res = max(res, query(u << 1 | 1, mid + 1, r, x, y));
  return res;
}
int maxDog;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    maxDog = max(maxDog, a[i]);
  }
  for (int i = 1; i <= n; i++) {
    int t = 0;
    if (a[i] - k >= 0 && a[i] + k <= maxDog)
      t = query(1, 1, n, a[i] - k, a[i] + k) + 1;
    update(1, 1, n, a[i], t);
  }
  printf("%d\n", query(1, 1, n, 1, n));
  return 0;
}
