#include <bits/stdc++.h>
using namespace std;
struct RMst {
  vector<int> d;
  int zero;
  RMst(int sz, int num) {
    int x = 1;
    while (x < sz) x *= 2;
    zero = x;
    d.resize(sz * 2, num);
  }
  void setnum(int di, int num) {
    di += zero;
    d[di] = num;
    di /= 2;
    while (di >= 1 && d[di] < num) {
      d[di] = max(d[di * 2], d[di * 2 + 1]);
      di /= 2;
    }
    return;
  }
  int ranmax(int l, int r) {
    if (l >= r) return -1;
    int x = -1001001001;
    l += zero;
    r += zero;
    while (1) {
      if (l % 2 == 1) {
        x = max(x, d[l]);
        ++l;
      }
      if (r % 2 == 1) {
        x = max(x, d[r - 1]);
        --r;
      }
      if (l == r) break;
      l /= 2;
      r /= 2;
    }
    return x;
  }
};
int main() {
  int n, k;
  cin >> n >> k;
  RMst dp(300005, 0);
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    int l = max(0, a - k);
    int r = min(300003, a + k + 1);
    dp.setnum(a, dp.ranmax(l, r) + 1);
  }
  cout << dp.ranmax(0, 300005) << endl;
}
