#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
using namespace std;
int n, a[300005], k, dp[300005], ab[3000005], st, fn, mx, pos, val;
void Update(int, int, int);
void Query(int, int, int);
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    st = max(0, a[i] - k);
    fn = min(300000, a[i] + k);
    mx = -1;
    Query(1, 1, n);
    dp[a[i]] = mx + 1;
    pos = a[i];
    val = dp[a[i]];
    Update(1, 1, n);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, dp[a[i]]);
  }
  cout << ans << '\n';
}
void Update(int nod, int left, int right) {
  if (left == right) {
    ab[nod] = val;
    return;
  }
  int mid = (left + right) / 2;
  if (pos <= mid) {
    Update(2 * nod, left, mid);
  } else
    Update(2 * nod + 1, mid + 1, right);
  ab[nod] = max(ab[2 * nod], ab[2 * nod + 1]);
}
void Query(int nod, int left, int right) {
  if (st <= left && right <= fn) {
    if (mx < ab[nod]) {
      mx = ab[nod];
    }
    return;
  }
  int mid = (left + right) / 2;
  if (st <= mid) Query(2 * nod, left, mid);
  if (mid < fn) Query(2 * nod + 1, mid + 1, right);
}
