#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
int n, m, a[N];
struct SegTree {
  int l[N], r[N], maxn[N];
  void build(int x, int ql, int qr) {
    l[x] = ql;
    r[x] = qr;
    if (ql == qr) return;
    int mid = (ql + qr) >> 1;
    build(x * 2, ql, mid);
    build(x * 2 + 1, mid + 1, qr);
  }
  int query(int x, int ql, int qr) {
    if (l[x] == ql && r[x] == qr) return maxn[x];
    int mid = (l[x] + r[x]) >> 1;
    if (qr <= mid) return query(x * 2, ql, qr);
    if (ql > mid) return query(x * 2 + 1, ql, qr);
    return max(query(x * 2, ql, mid), query(x * 2 + 1, mid + 1, qr));
  }
  void update(int x, int p, int v) {
    if (l[x] == p && r[x] == p) {
      maxn[x] = max(maxn[x], v);
      return;
    }
    int mid = (l[x] + r[x]) >> 1;
    if (p <= mid)
      update(x * 2, p, v);
    else
      update(x * 2 + 1, p, v);
    maxn[x] = max(maxn[x * 2], maxn[x * 2 + 1]);
  }
} seg;
int main() {
  scanf("%d%d", &n, &m);
  seg.build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    seg.update(1, a[i], seg.query(1, max(1, a[i] - m), min(n, a[i] + m)) + 1);
  }
  printf("%d\n", seg.maxn[1]);
  return 0;
}
