#include <bits/stdc++.h>
using namespace std;
long long values[41];
void value() {
  values[0] = 1;
  for (long long i = 1; i <= 40; i++) {
    values[i] = 2 * values[i - 1];
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  long long s[n + 1];
  for (long long i = 0; i < n; i++) cin >> s[i];
  vector<long long> dp(n, 0);
  auto solve = [&]() {
    map<long long, long long> ma;
    for (long long i = 0; i < n; i++) {
      long long curr = s[i];
      long long low = max(curr - k, 0ll);
      long long high = min(curr + k, n);
      for (long long j = low; j < high + 1; j++) dp[i] = max(dp[i], ma[j] + 1);
      ma[curr] = max(dp[i], ma[curr]);
    }
    long long ans = 0;
    for (long long i : dp) ans = max(i, ans);
    return ans;
  };
  cout << solve() << endl;
}
