#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int _i = 0; _i < n; _i++) cin >> a[_i];
  multimap<int, pair<int, int> > dp;
  dp.insert({a[0], {1, 1}});
  int lastF = 1, lastS = 1;
  for (int i = 1; i < n; ++i) {
    pair<int, pair<int, int> > cur = {a[i], {1, 0}};
    auto it1 = dp.lower_bound(a[i] - k);
    for (auto e = it1; e != dp.end() && abs(e->first - a[i]) <= k; e++) {
      cur.second.first = max(cur.second.first, e->second.first + 1);
    }
    cur.second.second = max(lastF, lastS);
    lastS = cur.second.second;
    lastF = cur.second.first;
    dp.insert(cur);
  }
  cout << max(lastF, lastS) << endl;
}
