#include <bits/stdc++.h>

#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<int, int>;

int op(int a, int b) { return max(a, b); }

int e() { return -1; }

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> dp(n);
  segtree<int, op, e> seg(300001);
  dp[0] = 1;
  seg.set(a[0], 1);
  for (int i = 1; i < n; i++) {
    int max_dp = seg.prod(max(0, a[i] - k), min(300000, a[i] + k + 1));
    if (max_dp == -1) {
      dp[i] = 1;
    } else {
      dp[i] = max_dp + 1;
    }
    seg.set(a[i], dp[i]);
  }
  cout << dp[n - 1] << endl;

  return 0;
}