#include <bits/stdc++.h>
using namespace std;
using pll = pair<long long, long long>;
const long long INF = 1LL << 60;
const long long MM = 1000000000;
const long long MOD = MM + 7;
const long long MMM = 9223372036854775807;
long long GCD(long long x, long long y) {
  if (y == 0)
    return x;
  else
    return GCD(y, x % y);
}
long long LCM(long long x, long long y) { return x / GCD(x, y) * y; }
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename A, size_t N, typename T>
void FILL(A (&array)[N], const T& val) {
  fill((T*)array, (T*)(array + N), val);
}
long long dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
long long ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1},
          ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
long long dp[300010];
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    dp[i] = 1;
    for (long long j = 0; j < i; j++) {
      if (abs(a[j] - a[i]) <= k) {
        chmax(dp[i], dp[j] + 1);
      }
    }
    chmax(ans, dp[i]);
  }
  cout << ans << endl;
}
