#include <bits/stdc++.h>
using namespace std;
int dp[4 * 300000 + 5];
int n, x, k;
int qry(int ni, int ns, int ne, int nl, int nr) {
  if (nl <= ns && ne <= nr) return dp[ni];
  if (nr < ns || ne < nl) return 0;
  int mid = ns + (ne - ns) / 2;
  int l = ni * 2 + 1, r = ni * 2 + 2;
  int x = qry(l, ns, mid, nl, nr);
  int y = qry(r, mid + 1, ne, nl, nr);
  return max(x, y);
}
int upd(int ni, int ns, int ne, int idx, int val) {
  if (ne < idx || idx < ns) return dp[ni];
  if (ns == ne) return dp[ni] = val;
  int mid = ns + (ne - ns) / 2;
  int l = ni * 2 + 1, r = ni * 2 + 2;
  int x = upd(l, ns, mid, idx, val);
  int y = upd(r, mid + 1, ne, idx, val);
  return dp[ni] = max(x, y);
}
signed main() {
  cin >> n >> k;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    int q = 1 + qry(0, 0, (int)3e5, max(1, x - k), min((int)3e5, x + k));
    ans = max(ans, q);
    upd(0, 0, (int)3e5, x, q);
  }
  cout << ans << endl;
  return 0;
}
