#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpii = vector<pii>;
template <typename X>
bool max_u(X& m, X v) {
  if (m < v) {
    m = v;
    return true;
  }
  return false;
}
template <typename X>
bool min_u(X& m, X v) {
  if (m > v) {
    m = v;
    return true;
  }
  return false;
}
struct solve {
  solve() {}
  int operator()(vi& a, int k) {
    int n = a.size();
    vi c(300000 + 1, 0);
    int ans = 0;
    for (int i = 0; i < n; i++) {
      int fill_min = max(a[i] - k, 0);
      int fill_max = min(a[i] + k, 300000);
      int val = c[a[i]] + 1;
      for (int j = fill_min; j <= fill_max; j++) {
        max_u(c[j], val);
      }
    }
    for (auto& m : c) max_u(ans, m);
    return ans;
  }
};
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  for (;;) {
    int n, k;
    cin >> n >> k;
    if (cin.fail()) break;
    vi a(n);
    for (auto& m : a) cin >> m;
    cout << solve()(a, k) << "\n";
  }
  return 0;
}
