#include <bits/stdc++.h>
using namespace std;
int Read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, k, f[300055], maxn[1200055], a[300055];
void modify(int o, int l, int r, int pos, int x) {
  if (l == r) {
    maxn[o] = max(maxn[o], x);
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    modify(o << 1, l, mid, pos, x);
  else
    modify(o << 1 | 1, mid + 1, r, pos, x);
  maxn[o] = max(maxn[o << 1], maxn[o << 1 | 1]);
}
int query(int o, int l, int r, int nl, int nr) {
  if (nl <= l && r <= nr) return maxn[o];
  int mid = (l + r) >> 1, ans = 0;
  if (nl <= mid) ans = max(ans, query(o << 1, l, mid, nl, nr));
  if (mid < nr) ans = max(ans, query(o << 1 | 1, mid + 1, r, nl, nr));
  return ans;
}
signed main() {
  n = Read(), k = Read();
  for (int i = 1; i <= n; i++) a[i] = Read() + 1;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    f[i] = query(1, 1, n, a[i] - k, a[i] + k) + 1;
    modify(1, 1, n, a[i], f[i]);
    ans = max(ans, f[i]);
  }
  cout << ans << endl;
  return 0;
}
