#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int M = 3e5 + 7;
int a[M], tr[M << 2];
int f[M], sz;
void up(int o, int l, int r, int x, int d) {
  if (l == r) {
    tr[o] = max(tr[o], d);
    return;
  }
  int m = (l + r) / 2;
  if (x <= m)
    up((o << 1), l, m, x, d);
  else
    up((o << 1 | 1), m + 1, r, x, d);
  tr[o] = max(tr[(o << 1)], tr[(o << 1 | 1)]);
}
int qu(int o, int l, int r, int x, int y) {
  if (x <= l && r <= y) {
    return tr[o];
  }
  int m = (l + r) / 2, mx = 0;
  if (x <= m) mx = max(mx, qu((o << 1), l, m, x, y));
  if (y > m) mx = max(mx, qu((o << 1 | 1), m + 1, r, x, y));
  return mx;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, sz = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i]++;
    sz = max(sz, a[i]);
  }
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    int tp = qu(1, 1, sz, max(1, a[i] - k), min(sz, a[i] + k)) + 1;
    up(1, 1, sz, a[i], tp);
    mx = max(mx, tp);
  }
  cout << mx << endl;
  return 0;
}
