/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Aman
 */


#include<bits/stdc++.h>
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb          push_back
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define rep(i, a, b)    for(ll i=a;i<=b;i++)
#define repr(i, a, b) for(ll i=a;i>=b;i--)
#define pll pair<ll, ll>
#define tp tuple<ll,ll>

template<int D, typename T>
struct vec : public vector<vec<D - 1, T>> {
  static_assert(D >= 1,
				"Vector dimension must be greater than zero!");

  template<typename... Args>
  vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) {
  }
};

template<typename T>
struct vec<1, T> : public vector<T> {
  vec(int n = 0, T val = T()) : vector<T>(n, val) {
  }
};

template<typename T>
inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }

template<typename T>
inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }

template<typename T, typename S>
ostream &operator<<(ostream &os, const pair<T, S> &v) {
  os << "(";
  os << v.first << ", "
	 << v.second << ")";
  return os;
}

template<typename T, typename S>
ostream &operator<<(ostream &os, const map<T, S> &v) {

  for (auto it : v)
	os << "[" << it.first << " : "
	   << it.second << "]";

  return os;
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  os << "[";
  for (auto it : v) {
	os << it;
	if (it != *v.rbegin())
	  os << ", ";
  }
  os << "]\n";
  return os;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  for (int i = 0; i < v.size(); ++i) {
	os << v[i];
	if (i != v.size() - 1)
	  os << ", ";
  }
  os << "]\n";
  return os;
}

template<typename T, typename U>
struct seg_tree_lazy {
  int S, H;

  T zero;
  vector<T> value;

  U noop;
  vector<bool> dirty;
  vector<U> prop;

  seg_tree_lazy<T, U>(int _S, T _zero = T(), U _noop = U()) {
	zero = _zero, noop = _noop;
	for (S = 1, H = 1; S < _S;) S *= 2, H++;

	value.resize(2 * S, zero);
	dirty.resize(2 * S, false);
	prop.resize(2 * S, noop);
  }

  void set_leaves(vector<T> &leaves) {
	copy(leaves.begin(), leaves.end(), value.begin() + S);
	fill(value.begin() + S + leaves.size(), value.end(), zero);

	for (int i = S - 1; i > 0; i--)
	  value[i] = value[2 * i] + value[2 * i + 1];
  }

  void apply(int i, U &update) {
	value[i] = update(value[i]);
	if (i < S) {
	  prop[i] = prop[i] + update;
	  dirty[i] = true;
	}
  }

  void rebuild(int i) {
	for (int l = i / 2; l; l /= 2) {
	  T combined = value[2 * l] + value[2 * l + 1];
	  value[l] = prop[l](combined);
	}
  }

  void propagate(int i) {
	for (int h = H; h > 0; h--) {
	  int l = i >> h;

	  if (dirty[l]) {
		apply(2 * l, prop[l]);
		apply(2 * l + 1, prop[l]);

		prop[l] = noop;
		dirty[l] = false;
	  }
	}
  }

  void upd(int i, int j, U update) {
	i += S, j += S;
	propagate(i), propagate(j);

	for (int l = i, r = j; l <= r; l /= 2, r /= 2) {
	  if ((l & 1) == 1) apply(l++, update);
	  if ((r & 1) == 0) apply(r--, update);
	}

	rebuild(i), rebuild(j);
  }

  T query(int i, int j) {
	i += S, j += S;
	propagate(i), propagate(j);

	T res_left = zero, res_right = zero;
	for (; i <= j; i /= 2, j /= 2) {
	  if ((i & 1) == 1) res_left = res_left + value[i++];
	  if ((j & 1) == 0) res_right = value[j--] + res_right;
	}
	return res_left + res_right;
  }
};

struct node {
  ll mx;

  node operator+(const node &n) {
	return {max(mx, n.mx)};
  }
};

struct update {
  ll mx;
  node operator()(const node &n) {
	return {max(n.mx, mx)};
  }

  update operator+(const update &u) {
	return {max(mx, u.mx)};
  }
};
class DFlatSubsequence {
 public:
  void solve(std::istream &cin, std::ostream &cout) {
	ll n, k, x, ans = 1;
	cin >> n >> k;
	seg_tree_lazy<node, update> lazy(300005);
	V<node> a(300005, {0});
	lazy.set_leaves(a);
	rep(i, 0, n - 1) {
	  cin >> x;
	  ll y = lazy.query(max(x - k,0ll), min(x + k,300005ll)).mx + 1;
	  ans = max(ans, y);
	  lazy.upd(x, x, {y});
	}
	cout << ans;

  }
};


int main() {
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	DFlatSubsequence solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 22212