#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void debug() { cerr << "]\n"; }
template <class H, class... T>
void debug(H h, T... t) {
  cerr << h;
  if (sizeof...(t)) {
    cerr << ", ";
  }
  debug(t...);
}
int n, k;
vector<int> a;
bool check(int len) {
  multiset<pair<int, int>> s;
  vector<int> dp(n, 1);
  s.insert({a[0], 0});
  for (int i = 1; i < n; i++) {
    multiset<pair<int, int>>::iterator it = s.lower_bound({a[i] - k, -1});
    while (it != s.end() && (*it).first <= a[i]) {
      if (dp[i] <= dp[(*it).second] + 1) {
        dp[i] = dp[(*it).second] + 1;
        s.erase(it++);
        continue;
      }
      it++;
    }
    it = s.lower_bound({a[i], -1});
    while (it != s.end() && (*it).first <= a[i] + k) {
      if (dp[i] <= dp[(*it).second] + 1) {
        dp[i] = dp[(*it).second] + 1;
        s.erase(it++);
        continue;
      }
      it++;
    }
    s.insert(make_pair(a[i], i));
  }
  for (int i = 0; i < n; i++) {
    if (dp[i] >= len) {
      return true;
    }
  }
  return false;
}
void solve() {
  cin >> n >> k;
  a = vector<int>(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int l = 0, r = n;
  while (r - l > 1) {
    int mid = (l + (r - l) / 2);
    if (check(mid)) {
      l = mid;
    } else {
      r = mid;
    }
  }
  cout << l << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int _;
  _ = 1;
  for (int i = 1; i <= _; i++) {
    solve();
  }
  return 0;
}
