#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
template <class T>
inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1002003004;
const ll LINF = 1002003004005006007ll;
struct preprocess {
  preprocess() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} ____;
template <typename T>
struct SegmentTree {
  using Func = function<T(T, T)>;
  int sz;
  vector<T> data;
  T identity;
  Func f;
  SegmentTree(int n, const T &identity, Func f) : identity(identity), f(f) {
    sz = 1;
    while (sz < n) sz <<= 1;
    data.assign(2 * sz, identity);
  }
  void set(int idx, const T &val) { data[idx + sz] = val; }
  void build() {
    for (int idx = sz - 1; idx > 0; idx--) {
      data[idx] = f(data[2 * idx], data[2 * idx + 1]);
    }
  }
  void update(int idx, const T &x) {
    idx += sz;
    data[idx] = x;
    while (idx >>= 1) {
      data[idx] = f(data[2 * idx], data[2 * idx + 1]);
    }
  }
  T query(int a, int b) { return query(a, b, 1, 0, sz); }
  T query(int a, int b, int idx, int l, int r) {
    if (r <= a || b <= l) return identity;
    if (a <= l && r <= b)
      return data[idx];
    else {
      T vl = query(a, b, idx * 2, l, (l + r) / 2);
      T vr = query(a, b, idx * 2 + 1, (l + r) / 2, r);
      return f(vl, vr);
    }
  }
  T operator[](const int &idx) const { return data[idx + sz]; }
};
int f(int a, int b) { return max(a, b); }
int main() {
  int MX = 300006;
  int n, k;
  cin >> n >> k;
  vi a(n);
  for (int i = 0; i < (int)(n); i++) cin >> a[i];
  SegmentTree<int> sg(MX, 0, f);
  for (int i = 0; i < (int)(n); i++) {
    int l = max(0, a[i] - k);
    int r = min(n, a[i] + k) + 1;
    int now = sg.query(l, r) + 1;
    sg.update(a[i], now);
  }
  cout << sg.query(0, MX) << '\n';
}
