#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1 * INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1 * LLINF;
template <class Ch, class Tr, class Container>
basic_ostream<Ch, Tr>& operator<<(basic_ostream<Ch, Tr>& os,
                                  Container const& x) {
  os << "{ ";
  for (auto& y : x) os << y << " ";
  return os << "}";
}
template <class X, class Y>
ostream& operator<<(ostream& os, pair<X, Y> const& p) {
  return os << "[ " << p.first << ", " << p.second << "]";
}
const long long MOD = 1e9 + 7;
struct SegTree {
  const int n;
  vector<int> T;
  SegTree(int size) : n(size) { T = vector<int>(4 * n + 1, 0); }
  void update(int index, int val, int v, int tl, int tr) {
    if (tl == tr) {
      T[v] = val;
    } else {
      int mid = (tl + tr) / 2;
      if (index <= mid) {
        update(index, val, 2 * v, tl, mid);
      } else {
        update(index, val, 2 * v + 1, mid + 1, tr);
      }
      T[v] = max(T[2 * v], T[2 * v + 1]);
    }
  }
  void update(int index, int val) { update(index, val, 1, 0, n - 1); }
  int get_max(int l, int r, int v, int tl, int tr) {
    if (l > tr or r < tl) return 0;
    if (l <= tl and tr <= r) return T[v];
    int mid = (tl + tr) / 2;
    int L = get_max(l, r, 2 * v, tl, mid);
    int R = get_max(l, r, 2 * v + 1, mid + 1, tr);
    return max(L, R);
  }
  int get_max(int l, int r) { return get_max(l, r, 1, 0, n - 1); }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int ans = 0;
  int n, k;
  cin >> n >> k;
  SegTree st = SegTree(300000);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    int top = min(x + k, 300000);
    int bot = max(0, x - k);
    int prev_max = st.get_max(bot, top);
    ans = max(ans, 1 + prev_max);
    st.update(x, ans);
  }
  cout << ans;
}
