#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, K;
  cin >> N >> K;
  vector<long long> A(N);
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
  }
  long long dp[300300] = {0};
  long long maxx = 0;
  for (long long i = 0; i < N; i++) {
    for (long long j = i + 1; j < N; j++) {
      if (abs(A[i] - A[j]) <= K) {
        dp[j] = max(dp[i] + 1, dp[j]);
      }
    }
  }
  cout << (*max_element(dp, dp + N)) + 1LL << endl;
}
