#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long dx[] = {-1, 1, 0, 0};
long long dy[] = {0, 0, 1, -1};
const long long inf = 1e12;
bool test = 0;
long long n, k, x;
void solve() {
  cin >> n >> k;
  unordered_map<long long, long long> m;
  set<long long> st;
  set<long long> small, big;
  for (long long i = 1; i <= n; ++i) {
    cin >> x;
    auto r = upper_bound(st.begin(), st.end(), x + k);
    auto l = upper_bound(st.begin(), st.end(), x - k - 1);
    m[x] = 1;
    for (auto it = l; it != r; it++) {
      long long x1 = m[*it];
      if (*it > x) {
        if (big.find(*it) != big.end()) {
          big.erase(*it);
          st.erase(*it);
        } else
          small.insert(*it);
      } else {
        if (small.find(*it) != small.end()) {
          small.erase(*it);
          st.erase(*it);
        } else
          big.insert(*it);
      }
      m[x] = max(m[x], x1 + 1);
    }
    st.insert(x);
  }
  long long ans = 0;
  for (auto it : st) ans = max(ans, m[it]);
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  if (test) cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
