#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int N, K;
  cin >> N >> K;
  vector<int> nums(N, 0);
  for (int i = 0; i < N; i++) cin >> nums[i];
  int longest = 0;
  vector<int> dp(N, 1);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      if (abs(nums[i] - nums[j]) <= K) dp[i] = max(dp[i], dp[j] + 1);
    }
    longest = max(longest, dp[i]);
  }
  std::cout << longest << "\n";
  return 0;
}
