#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n + 5);
  vector<int> dp(n + 5, 0);
  for (int i = 1; i <= n; i++) cin >> a[i];
  int mx = 1;
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    dp[i] = 1;
    for (int j = i - 1; j >= 1; j--) {
      if (a[i] - k <= a[j] && a[j] <= a[i] + k) {
        dp[i] = max(dp[i], 1 + dp[j]);
      }
    }
    mx = max(mx, dp[i]);
  }
  cout << mx << "\n";
  return 0;
}
