#include <bits/stdc++.h>
using namespace std;
int N, K;
int A[303030];
int dp[303030];
int dp_dfs(int n) {
  if (dp[n] != 0) return dp[n];
  int max_len = 1;
  for (int i = n + 1; i < N; i++) {
    if (A[n] - K <= A[i] && A[i] <= A[n] + K) {
      max_len = max(max_len, dp_dfs(i) + 1);
    }
  }
  return dp[n] = max_len;
}
int main() {
  cin >> N >> K;
  for (size_t i = 0; i < N; i++) {
    cin >> A[i];
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, dp_dfs(i));
  }
  cout << ans << endl;
  return 0;
}
