#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
template <typename T>
class SegTree {
  int n;
  vector<T> data;
  T def;
  function<T(T, T)> operation;
  function<T(T, T)> update;
  T _query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return def;
    if (a <= l && r <= b)
      return data[k];
    else {
      T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2);
      T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r);
      return operation(c1, c2);
    }
  }

 public:
  SegTree(int _n, T _def, function<T(T, T)> _operation,
          function<T(T, T)> _update)
      : def(_def), operation(_operation), update(_update) {
    n = 1;
    while (n < _n) {
      n *= 2;
    }
    data = vector<T>(2 * n - 1, def);
  }
  void change(int i, T x) {
    i += n - 1;
    data[i] = update(data[i], x);
    while (i > 0) {
      i = (i - 1) / 2;
      data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }
  T query(int a, int b) { return _query(a, b, 0, 0, n); }
  T operator[](int i) { return data[i + n - 1]; }
  T get(int i) { return data[i + n - 1]; }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  SegTree<int> st(
      300100, 0, [](int a, int b) { return max(a, b); },
      [](int a, int b) { return b; });
  int a[300100];
  for (int i = (0); i < (int)(n); i++) cin >> a[i];
  for (int i = (0); i < (int)(n); i++) {
    int l = max(0, a[i] - k);
    int r = min(n, a[i] + k + 1);
    int tmp = st.query(l, r);
    if (st.get(a[i]) < tmp + 1) {
      st.change(a[i], tmp + 1);
    }
  }
  int ans = st.query(0, n);
  cout << ans << endl;
  return 0;
}
