#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename T>
struct SegmentTree {
 private:
  int n;
  vector<T> node;
  T identity;

 public:
  T merge(T x, T y) { return max(x, y); }
  SegmentTree(vector<T> v, T id) {
    int sz = (int)v.size();
    n = 1;
    while (n < sz) n *= 2;
    identity = id;
    node.resize(2 * n - 1, id);
    for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; i--) {
      node[i] = merge(node[2 * i + 1], node[2 * i + 2]);
    }
  }
  void update(int x, T val) {
    x += (n - 1);
    node[x] = val;
    while (x > 0) {
      x = (x - 1) / 2;
      node[x] = merge(node[2 * x + 1], node[2 * x + 2]);
    }
  }
  T query(int a, int b, int idx = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return identity;
    if (a <= l && r <= b) return node[idx];
    T vl = query(a, b, 2 * idx + 1, l, (l + r) / 2);
    T vr = query(a, b, 2 * idx + 2, (l + r) / 2, r);
    return merge(vl, vr);
  };
  T operator[](int k) { return node[k + n - 1]; }
};
signed main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int k;
  cin >> k;
  vector<int> dp(n, 0);
  dp[0] = 1;
  SegmentTree<int> seg(dp, 0);
  vector<int> a(n);
  vector<int> b(n);
  vector<pair<int, int> > c(n);
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    b[i] = a[i];
    c[i].first = a[i];
    c[i].second = i;
  }
  sort((a).begin(), (a).end());
  sort((c).begin(), (c).end());
  vector<int> num(n);
  for (int i = 0; i < (n); i++) {
    num[c[i].second] = i;
  }
  for (int i = 0; i < (n); i++) {
    if (i == 0) continue;
    int lf = lower_bound((a).begin(), (a).end(), b[i] - k) - a.begin();
    int rf = upper_bound((a).begin(), (a).end(), b[i] + k) - a.begin();
    int mx = seg.query(lf, rf);
    seg.update(num[i], mx + 1);
  }
  cout << seg.query(0, n) << endl;
}
