#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7;
int T;
int n, m;
int a[N], p[N], tot;
struct node {
  int mx, l, r;
} t[N << 2];
inline void build(int p, int l, int r) {
  t[p].l = l, t[p].r = r;
  if (l == r) {
    t[p].mx = 0;
    return;
  }
  int mid = l + r >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  t[p].mx = 0;
}
inline void update(int p, int x, int v) {
  if (t[p].l == t[p].r) {
    t[p].mx = v;
    return;
  }
  int mid = (t[p].l + t[p].r) >> 1;
  if (x <= mid)
    update(p << 1, x, v);
  else
    update(p << 1 | 1, x, v);
  t[p].mx = max(t[p << 1].mx, t[p << 1 | 1].mx);
}
inline int ask(int p, int l, int r) {
  if (l <= t[p].l && t[p].r <= r) return t[p].mx;
  int mid = (t[p].l + t[p].r) >> 1;
  int ret = 0;
  if (l <= mid) ret = max(ret, ask(p << 1, l, r));
  if (r > mid) ret = max(ret, ask(p << 1 | 1, l, r));
  return ret;
}
int main() {
  scanf("%d", &n), scanf("%d", &m);
  int ans = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  build(1, 1, n);
  for (int i = 1, t; i <= n; i++) {
    t = ask(1, max(1, a[i] - m), min(n, a[i] + m));
    update(1, a[i], t + 1);
    ans = max(ans, t + 1);
  }
  printf("%d\n", ans);
  return 0;
}
