#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int& ai : a) cin >> ai;
  vector<int> dp(n);
  for (int i = n - 1; i >= 0; --i) {
    for (int j = i; j < n; ++j) {
      dp[i] = max(dp[i], dp[j] + ((abs(a[i] - a[j]) <= k) ? 1 : 0));
    }
  }
  int ret = *max_element(dp.begin(), dp.end());
  cout << ret << endl;
  return 0;
}
