#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
static const double PI = acos(-1);
static const int INF = 1e9 + 7;
template <typename T>
void view(T e) {
  cout << e << endl;
}
template <typename T>
void view(const vector<T>& v) {
  for (const auto& e : v) {
    cout << e << " ";
  }
  cout << endl;
}
template <typename T>
void view(const vector<vector<T> >& vv) {
  for (const auto& v : vv) {
    view(v);
  }
}
ll seg[1 << 20];
void set_value(ll pos, ll val) {
  pos += 1 << 19;
  seg[pos] = val;
  while ((pos /= 2) > 0) {
    seg[pos] = max(seg[pos * 2], seg[pos * 2 + 1]);
  }
}
ll get_max(ll ql, ll qr, ll sl = 0, ll sr = 1 << 19, ll pos = 1) {
  if (qr <= sl || sr <= ql) return 0;
  if (ql <= sl && sr <= qr) return seg[pos];
  ll sm = (sl + sr) / 2;
  ll lmax = get_max(ql, qr, sl, sm, pos * 2);
  ll rmax = get_max(ql, qr, sm, sr, pos * 2 + 1);
  return max(lmax, rmax);
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  for (int i = 0; i < (n + 1); ++i) {
    set_value(i, 0);
  }
  for (int i = 0; i < (n); ++i) {
    int add = get_max(max(a[i] - k, 0), min(a[i] + k + 1, n + 1));
    set_value(a[i], add + 1);
  }
  int ans = get_max(0, n + 1);
  cout << ans << endl;
  return 0;
}
