#include <bits/stdc++.h>
using namespace std;
const int N = 500100;
int num[N];
struct node {
  int l, r;
  long long val, lazy;
} tree[N * 4];
void push_up(int rt) {
  tree[rt].val = max(tree[rt << 1].val, tree[rt << 1 | 1].val);
}
void push_down(int rt) {
  if (tree[rt].lazy) {
    tree[rt << 1].lazy += tree[rt].lazy;
    tree[rt << 1 | 1].lazy += tree[rt].lazy;
    {
      tree[rt << 1].val += tree[rt].lazy;
      tree[rt << 1 | 1].val += tree[rt].lazy;
    }
    tree[rt].lazy = 0;
  }
}
void build(int rt, int l, int r) {
  tree[rt].l = l, tree[rt].r = r;
  tree[rt].lazy = 0;
  if (l == r) {
    tree[rt].val = 0;
    return;
  } else {
    int mid = l + r >> 1;
    build(rt << 1, l, mid);
    build(rt << 1 | 1, mid + 1, r);
    push_up(rt);
  }
}
void update_point(int rt, int pos, long long val) {
  if (tree[rt].l == tree[rt].r && pos == tree[rt].l) {
    tree[rt].val = val;
    return;
  }
  int mid = tree[rt].l + tree[rt].r >> 1;
  if (pos <= mid)
    update_point(rt << 1, pos, val);
  else
    update_point(rt << 1 | 1, pos, val);
  push_up(rt);
}
long long query_interval(int rt, int l, int r) {
  if (l <= tree[rt].l && r >= tree[rt].r) return tree[rt].val;
  push_down(rt);
  int mid = tree[rt].l + tree[rt].r >> 1;
  if (r <= mid)
    return query_interval(rt << 1, l, r);
  else if (l > mid)
    return query_interval(rt << 1 | 1, l, r);
  else {
    return max(query_interval(rt << 1, l, mid),
               query_interval(rt << 1 | 1, mid + 1, r));
  }
}
void solve(int T) {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
  }
  build(1, 0, n);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int t = num[i];
    int l = max(0, t - k), r = min(300000, t + k);
    int q = query_interval(1, l, r);
    ans = max(ans, q + 1);
    update_point(1, t, q + 1);
  }
  printf("%d", ans);
}
signed main() {
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
  return 0;
}
