#include <bits/stdc++.h>
using namespace std;
struct XX {
  int x;
  int y;
  int i;
  int ans;
};
class xxGreater {
 public:
  bool operator()(const XX& riLeft, const XX& riRight) const {
    if ((riLeft.x) == (riRight.x)) {
      return riLeft.y < riRight.y;
    }
    return (riLeft.x) < (riRight.x);
  }
};
const int MAX_N = 300001;
int treesize, dat[4 * MAX_N];
void init(int n_) {
  treesize = 1;
  while (treesize < n_) treesize *= 2;
  for (int i = 0; i < 2 * treesize - 1; i++) dat[i] = 0;
}
void update(int k, int a) {
  k += treesize - 1;
  dat[k] = a;
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
  }
}
int query(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l) return 0;
  if (a <= l && r <= b)
    return dat[k];
  else {
    int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return max(vl, vr);
  }
}
int main(int argc, const char* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  int a[300000];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  init(n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int tmp =
        query(max(0, a[i] - k), min(a[i] + k + 1, 300001), 0, 0, treesize);
    update(a[i], tmp + 1);
  }
  ans = query(0, 300001, 0, 0, treesize);
  cout << ans << endl;
  return 0;
}
