#include <bits/stdc++.h>
using namespace std;
void testCase() {
  long long n, k;
  cin >> n >> k;
  stack<long long> st;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<long long> mx(n, -1);
  for (long long i = 0; i < n; i++) {
    while (st.size() && st.top() < a[i]) {
      st.pop();
    }
    if (st.size()) mx[i] = st.top();
    st.push(a[i]);
  }
  while (st.size()) {
    st.pop();
  }
  vector<long long> mn(n, -1);
  for (long long i = 0; i < n; i++) {
    while (st.size() && st.top() > a[i]) {
      st.pop();
    }
    if (st.size()) mn[i] = st.top();
    st.push(a[i]);
  }
  long long ans = 0;
  vector<long long> dp(n, 0);
  for (long long i = 0; i < n; i++) {
    if (mn[i] != -1 && abs(mn[i] - a[i]) <= k) {
      dp[i] = max(dp[i], dp[mn[i]] + 1);
    }
    if (mx[i] != -1 && abs(mx[i] - a[i]) <= k) {
      dp[i] = max(dp[i], dp[mx[i]] + 1);
    }
    if (i - 1 >= 0 && abs(a[i - 1] - a[i]) <= k) {
      dp[i] = max(dp[i], dp[i - 1] + 1);
    }
    dp[i] = max(dp[i], 1LL);
    ans = max(ans, dp[i]);
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) testCase();
  return 0;
}
