#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  int A[n], dp[n], m = 0;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    dp[i] = 0;
  }
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (abs(A[i] - A[j]) <= k) dp[j] = max(dp[j], dp[i] + 1);
    }
  }
  for (int i = 0; i < n; i++) {
    m = max(m, dp[i]);
  }
  cout << m << endl;
  return 0;
}
