#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
const int INT_INF = 1 << 29;
const int MAX = 300010;
const int MOD = 998244353;
using Graph = vector<vector<int>>;
int dp[MAX];
void solve() {
  int N, K;
  int A[MAX];
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> A[i];
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;
  for (int i = 1; i < N; i++) {
    int max_length = 0;
    for (int j = 0; j < i; j++) {
      if (A[j] - K <= A[i] && A[i] <= A[j] + K) chmax(max_length, dp[j]);
    }
    dp[i] = max_length + 1;
  }
  cout << *max_element(dp, dp + N);
  return;
}
int main() {
  solve();
  return 0;
}
