#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, N = 3e5;
struct RMQ {
  vector<int> t;
  int n;
  RMQ(int n) : n(n) { t.resize(n << 1, 0); }
  void build(int a[]) {
    for (int i = 0; i < n; i++) t[n + i] = a[i];
    for (int i = n - 1; i > 0; --i) t[i] = max(t[i << 1], t[i << 1 | 1]);
  }
  void modify(int p, int v) {
    v = max(v, t[p + n]);
    for (t[p += n] = v; p > 1; p >>= 1) t[p >> 1] = max(t[p], t[p ^ 1]);
  }
  int query(int l, int r) {
    int res = 0;
    for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
      if (l & 1) res = max(res, t[l++]);
      if (r & 1) res = max(res, t[--r]);
    }
    return res;
  }
} t(2 * N);
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k, ans = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    ++x;
    int l = max(1, x - k), r = min(N, x + k);
    int y = t.query(l, r) + 1;
    t.modify(x, y);
    ans = max(ans, y);
  }
  cout << ans << endl;
}
