#include <bits/stdc++.h>
using namespace std;
int dirx[] = {1, -1, 0, 0, 1, 1, -1, -1}, diry[] = {0, 0, 1, -1, 1, -1, 1, -1};
vector<int> seg(4 * 500000), inp(500000);
void upd(int cur, int strt, int en, int i, int v) {
  if (strt == en)
    seg[cur] = v;
  else {
    int mid = (strt + en) / 2;
    if (i <= mid)
      upd(2 * cur, strt, mid, i, v);
    else
      upd(2 * cur + 1, mid + 1, en, i, v);
    seg[cur] = max(seg[2 * cur], seg[2 * cur + 1]);
  }
}
int qry(int cur, int strt, int en, int l, int r) {
  if (en < l || strt > r) return INT_MIN;
  if (strt >= l && en <= r) return seg[cur];
  int mid = (strt + en) / 2;
  return max(qry(2 * cur, strt, mid, l, r),
             qry(2 * cur + 1, mid + 1, en, l, r));
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> inp[i];
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int rt = qry(1, 1, 300000, inp[i], min(inp[i] + k, 300000));
    int lf = qry(1, 1, 300000, max(0, inp[i] - k), inp[i]);
    int ac = max(rt, lf) + 1;
    ans = max(ans, ac);
    upd(1, 1, 300001, inp[i], ac);
  }
  cout << ans;
  return 0;
}
