#include <bits/stdc++.h>
using namespace std;
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
const int N = 3 * 1e5 + 1;
int n, k;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  set<int> os;
  map<int, int> mp;
  int a, mx;
  for (int i = 0; i < n; i++) {
    cin >> a;
    auto x = os.lower_bound(a - k);
    if (x == os.end()) {
      os.insert(a);
      mp[a] = 1;
    } else {
      mx = 0;
      while (*x <= a + k && x != os.end()) {
        mx = max(mx, mp[*x]);
        mp.erase(*x);
        os.erase(x);
        x++;
      }
      os.insert(a);
      mp[a] = mx + 1;
    }
  }
  int ans = 0;
  for (auto x : mp) ans = max(ans, x.second);
  cout << ans << '\n';
  return 0;
}
