#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (auto &x : a) cin >> x;
  ;
  long long maxx = 0;
  for (int i = 0; i < n; i++) maxx = max(maxx, a[i]);
  maxx += 1;
  map<long long, vector<long long> > make_pair;
  long long l = max((long long)0, a[0] - k), h = min(maxx, a[0] + k);
  for (int i = l; i < h + 1; i++) {
    make_pair[i].push_back(0);
  }
  vector<long long> dp(n);
  dp[0] = 1;
  long long ans = 1;
  for (int i = 1; i < n; i++) {
    dp[i] = 1;
    vector<long long> temp = make_pair[a[i]];
    for (int j = 0; j < (long long)temp.size(); j++) {
      dp[i] = max(dp[i], dp[temp[j]] + 1);
    }
    l = max((long long)0, a[i] - k);
    h = min(maxx, a[i] + k);
    for (int j = l; j < h + 1; j++) {
      make_pair[j].push_back(i);
    }
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
}
int main() {
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
