#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  vector<int> nums(N);
  for (int i = 0; i < N; i++) {
    cin >> nums[i];
  }
  deque<int> bigger, smaller;
  vector<int> dp(N);
  for (int i = 0; i < N; i++) {
    while (!bigger.empty() && nums[bigger.back()] < nums[i]) {
      bigger.pop_back();
    }
    if (!bigger.empty() && nums[bigger.back()] <= nums[i] + K) {
      dp[i] = max(dp[i], dp[bigger.back()] + 1);
    } else {
      dp[i] = max(dp[i], 1);
    }
    bigger.push_back(i);
    while (!smaller.empty() && nums[smaller.back()] > nums[i]) {
      smaller.pop_back();
    }
    if (!smaller.empty() && nums[smaller.back()] >= nums[i] - K) {
      dp[i] = max(dp[i], dp[smaller.back()] + 1);
    } else {
      dp[i] = max(dp[i], 1);
    }
    smaller.push_back(i);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, dp[i]);
  }
  cout << ans;
  return 0;
}
