#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 b[N];
struct BIT {
  int t[N], n;
  int a[N];
  void init(int n_) {
    n = n_;
    memset(t, 0, sizeof(t));
    memset(a, 0, sizeof(a));
  }
  int query(int l, int r) {
    int res = a[r];
    while (r > l) {
      for (--r; r - r & (-r) >= l; r -= r & (-r)) res = max(res, t[r]);
      res = max(res, a[r]);
    }
    return res;
  }
  void modify(int first, int v) {
    a[first] = v;
    while (first <= n) {
      t[first] = a[first];
      for (int i = 1, j = first & (-first); i < j; i <<= 1)
        t[first] = max(t[first], t[first - i]);
      first += first & (-first);
    }
  }
};
BIT tree;
int main() {
  ios::sync_with_stdio(false);
  int n, k, maxv = 1, res = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    b[i]++;
    maxv = max(maxv, b[i]);
  }
  tree.init(maxv);
  for (int i = 1; i <= n; i++) {
    int l = max(1, b[i] - k);
    int r = min(maxv, b[i] + k);
    int t = tree.query(l, r);
    res = max(res, t + 1);
    tree.modify(b[i], t + 1);
  }
  cout << res << endl;
  return 0;
}
