#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<vector<int>>;
const ll LINF = 1LL << 60;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
template <typename T>
bool chmin(T &a, const T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmax(T &a, const T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int N, K;
  cin >> N >> K;
  vi A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vi dp(N, 1);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      if (abs(A[i] - A[j]) <= K) chmax(dp[i], dp[j] + 1);
    }
    chmax(ans, dp[i]);
  }
  cout << ans << endl;
  return 0;
}
