#include <bits/stdc++.h>
int left[1500000], right[1500000], tree[1500000] = {0};
int a[400000], f[400000] = {0}, record[400000];
int min(int a, int b) {
  if (a < b)
    return a;
  else
    return b;
}
int max(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}
void build(int l, int r, int k) {
  tree[k] = 0;
  left[k] = l;
  right[k] = r;
  int mid = (l + r) / 2;
  if (l == r) {
    record[l] = k;
    return;
  }
  build(l, mid, k * 2);
  build(mid + 1, r, k * 2 + 1);
}
int find(int l, int r, int k) {
  if (r < left[k] || l > right[k]) return 0;
  if (left[k] >= l && right[k] <= r) return tree[k];
  int ans1 = find(l, r, k * 2);
  int ans2 = find(l, r, k * 2 + 1);
  return max(ans1, ans2);
}
void update(int l, int r, int num, int k) {
  if (r < left[k] || l > right[k]) return;
  if (left[k] >= l && right[k] <= r) {
    tree[k] = max(tree[k], num);
    if (left[k] == right[k]) return;
    update(l, r, num, k * 2);
    update(l, r, num, k * 2 + 1);
    return;
  }
  update(l, r, num, k * 2);
  update(l, r, num, k * 2 + 1);
  tree[k] = max(tree[k * 2], tree[k * 2 + 1]);
}
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  build(0, 300000, 1);
  for (int i = 1; i <= n; i++) {
    f[i] = tree[record[a[i]]] + 1;
    update(max(0, a[i] - k), min(a[i] + k, 300000), f[i], 1);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (f[i] > ans) ans = f[i];
  }
  printf("%d", ans);
}
