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