#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  for (long long i = 0; i < (long long)(n); i++) {
    int num;
    cin >> num;
    num--;
    bool isIsolate = true;
    int biggest = 0;
    auto it = mp.lower_bound(num - k);
    vector<int> vec;
    for (auto itt = it, e = mp.end();
         (itt != e) && (((*itt).first) <= (num + k)); ++itt) {
      isIsolate = false;
      biggest = max(biggest, (*itt).second);
      vec.push_back((*itt).first);
    }
    for (long long i = 0; i < (long long)(vec.size()); i++) mp.erase(vec[i]);
    if (isIsolate) {
      mp[num] = 1;
    } else {
      mp[num] = biggest + 1;
    }
  }
  int biggest = 0;
  for (long long i = 0; i < (long long)(300000); i++)
    biggest = max(biggest, mp[i]);
  cout << biggest << endl;
  return 0;
}
