#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T1, typename T2>
bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
int INF = -1e9;
struct SegmentTree {
 private:
  int n;
  vector<int> node;

 public:
  SegmentTree(vector<int> v) {
    int sz = v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1, INF);
    for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; i--)
      node[i] = max(node[2 * i + 1], node[2 * i + 2]);
  }
  void update(int x, int val) {
    x += (n - 1);
    node[x] = val;
    while (x > 0) {
      x = (x - 1) / 2;
      node[x] = max(node[2 * x + 1], node[2 * x + 2]);
    }
  }
  int getmax(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return INF;
    if (a <= l && r <= b) return node[k];
    int vl = getmax(a, b, 2 * k + 1, l, (l + r) / 2);
    int vr = getmax(a, b, 2 * k + 2, (l + r) / 2, r);
    return max(vl, vr);
  }
  int getleft(int x, int val, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= x || n <= l) return INF;
    if (x <= l && r <= n) {
      if (k >= n - 1) return (node[k] >= val ? k - n + 2 : INF);
      if (getmax(l, (l + r) / 2) >= val)
        return (getleft(x, val, 2 * k + 1, l, (l + r) / 2));
      if (getmax((l + r) / 2, r) >= val)
        return (getleft(x, val, 2 * k + 2, (l + r) / 2, r));
      return (INF);
    }
    int vl = getleft(x, val, 2 * k + 1, l, (l + r) / 2);
    int vr = getleft(x, val, 2 * k + 2, (l + r) / 2, r);
    if (vl != INF) return (vl);
    if (vr != INF) return (vr);
    return (INF);
  }
};
int main(void) {
  int n, k;
  cin >> n >> k;
  vector<int> a(300010);
  SegmentTree seg(a);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    ll low = max(a - k - 1, 0);
    ll high = min(a + k, 300001);
    ll val = seg.getmax(low, high);
    seg.update(a - 1, val + 1);
  }
  ll ans = seg.getmax(0, 300001);
  cout << ans << endl;
}
