#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  vector<int> A;
  cin >> N >> K;
  A.resize(N, 0);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  vector<int> C(300000, 0);
  for (int n = N - 1; n >= 0; --n) {
    int v = A[n];
    int begin = std::max(v - K, 0);
    int end = std::min(v + K + 1, N);
    C[v] = *max_element(C.begin() + begin, C.begin() + end) + 1;
  }
  cout << *max_element(C.begin(), C.end()) << endl;
  return 0;
}
