#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N, K;
  cin >> N >> K;
  ;
  set<pair<int, int> > sup, inf;
  int m = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    auto lowsup = sup.lower_bound({x + K, 0});
    auto lowinf = inf.lower_bound({x - K + 1, 0});
    int Qsup = 0, Qinf = 0;
    if (lowsup != sup.end()) Qsup = (*lowsup).second;
    if (!inf.empty() && lowinf != inf.begin()) Qinf = (*(prev(lowinf))).second;
    auto pos = sup.lower_bound({x, 0});
    auto succ = sup.lower_bound({x + 1, 0});
    if (pos != sup.end()) sup.erase(pos);
    int Qsucc = 0;
    if (succ != sup.end()) Qsucc = (*succ).second;
    sup.insert({x, Qsup + Qinf + 1 + Qsucc});
    pos = inf.lower_bound({x, 0});
    succ = inf.lower_bound({x, 0});
    if (pos != inf.end()) inf.erase(pos);
    Qsucc = 0;
    if (!inf.empty() && succ != inf.begin()) Qsucc = (*(prev(succ))).second;
    inf.insert({x, Qsup + Qinf + 1 + Qsucc});
    m = max(m, Qsup + Qinf + 1);
  }
  cout << (K == 0 ? N : m);
  return 0;
}
