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