#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const int N = 3e5 + 7;
int a[N], f[N];
struct BIT {
  int n, bit[N];
  void init() { memset(bit, 0, sizeof(bit)), memset(f, 0, sizeof(f)); }
  int query(int l, int r) {
    int res = f[r];
    for (; r > l;) {
      for (r--; r - r & (-r) >= l; r -= r & (-r)) res = max(res, bit[r]);
      res = max(res, f[r]);
    }
    return res;
  }
  void modify(int p, int v) {
    f[p] = v;
    for (int i = p; i <= n; i += i & (-i)) {
      bit[i] = v;
      for (int j = 1; j < i & (-i); j <<= 1) bit[i] = max(bit[i], bit[i - j]);
    }
  }
} tree;
int main() {
  ios::sync_with_stdio(false);
  int n, k, maxv = 0, res = 0;
  cin >> n >> k;
  tree.n = n;
  tree.init();
  for (int i = 1; i <= tree.n; i++) {
    cin >> a[i];
    maxv = max(maxv, a[i]);
  }
  for (int i = 1; i <= n; i++) {
    int l = max(0, a[i] - k);
    int r = min(maxv, a[i] + k);
    int t = tree.query(l, r);
    res = max(res, t + 1);
    tree.modify(a[i], t + 1);
  }
  cout << res << endl;
  return 0;
}
