#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];
    dp[i] = 1;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (abs(arr[j] - arr[i]) <= k) dp[j] = max(dp[j], dp[i] + 1);
    }
  }
  int ans(0);
  for (int i = 0; i < n; ++i) ans = max(ans, dp[i]);
  cout << ans;
}
