#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const long long LLINF = 1LL << 62;
int mod = 1000000007;
int N, K;
int L[1000000], R[1000000];
template <class 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, (k << 1) + 1, l, (l + r) / 2);
      T c2 = _query(a, b, (k << 1) + 2, (l + r) / 2, r);
      return operation(c1, c2);
    }
  }

 public:
  SegTree(size_t _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 << 1) + 1], data[(i << 1) + 2]);
    }
  }
  T query(int a, int b) { return _query(a, b, 0, 0, n); }
  T operator[](int i) { return data[i + n - 1]; }
};
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  SegTree<int> st(
      500000, 0, [](long long a, long long b) { return max(a, b); },
      [](long long a, long long b) { return b; });
  for (int i = 0; i < N; i++) {
    int left = max(0, A[i] - K);
    int right = min(300000, A[i] + K);
    int temp = st.query(left, right + 1);
    st.change(A[i], temp + 1);
  }
  cout << st.query(0, N) << endl;
  return 0;
}
