#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long N, K;
  cin >> N >> K;
  vector<long long> A(N);
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<long long> count(300001, 0);
  for (long long i = 0; i < N; i++) {
    long long precount = 0;
    for (long long j = A[i] - K; j <= A[i] + K; j++) {
      if (j > 0 && j <= 300000) {
        if (precount < count[j]) {
          precount = count[j];
        }
      }
    }
    count[A[i]] = precount + 1;
  }
  long long ans = 0;
  for (long long i = 1; i < 300001; i++) {
    if (ans < count[i]) {
      ans = count[i];
    }
  }
  cout << ans << endl;
}
