#include <bits/stdc++.h>
template <class T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
template <class T>
void view(T e) {
  cout << e << endl;
}
template <class T>
void view(const vector<T> &v) {
  for (const auto &e : v) {
    cout << e << " ";
  }
  cout << endl;
}
template <class T>
void view(const vector<vector<T>> &vv) {
  for (const auto &v : vv) {
    view(v);
  }
}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const int inf = 1 << 30;
const ll inf_l = 1LL << 61;
const int MAX = 300005;
template <class T>
struct segment_tree {
  using F = function<T(T, T)>;
  int n;
  vector<T> data;
  F f;
  T init_v;
  segment_tree(int n_, T init_v, F f) : f(f), init_v(init_v) {
    n = 1;
    while (n < n_) n *= 2;
    data.assign(2 * n - 1, init_v);
  }
  void update(int k, T a) {
    k += n - 1;
    data[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      data[k] = f(data[k * 2 + 1], data[k * 2 + 2]);
    }
  }
  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return init_v;
    if (a <= l && r <= b)
      return data[k];
    else {
      T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
      return f(vl, vr);
    }
  }
  T operator[](int a) { return data[a + n - 1]; }
  void debug_seg(int a, int b) {
    a += n - 1;
    b += n - 1;
    for (int i = a; i < b; i++) {
      cout << data[i] << " ";
    }
    cout << endl;
  }
};
int dp[MAX];
int main() {
  int n, k;
  cin >> n >> k;
  vint a(n);
  for (int i = 0; i < (int)(n); i++) cin >> a[i];
  auto f = [](int a, int b) { return max(a, b); };
  segment_tree<int> st(MAX, 0, f);
  for (int i = 1; i <= n; i++) {
    int l = max(a[i - 1] - k, 0);
    int r = a[i - 1] + k;
    dp[i] = st.query(l, r + 1) + 1;
    st.update(a[i - 1], dp[i]);
  }
  cout << dp[n] << endl;
}
