#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 5e18;
const long long mod1 = 998244353;
const long long nax = 300007;
long long n, a[nax], dp[nax], k;
map<long long, long long> mp;
void solve() {
  cin >> n >> k;
  for (long long i = (0); i < (n); i++) {
    cin >> a[i];
    mp[a[i]] = 0;
  }
  for (long long i = (n - 1); i > (-1); --i) {
    auto it = --mp.upper_bound(a[i] + k);
    while (it != mp.end() && it->first >= a[i] - k) {
      dp[i] = max(dp[i], it->second + 1);
      if (it == mp.begin()) break;
      it--;
    }
    mp[a[i]] = max(dp[i], mp[a[i]]);
  }
  long long ans = *max_element(dp, dp + n);
  cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
