#include <bits/stdc++.h>
using namespace std;
long long modd = 1000 * 1000 * 1000 + 7;
template <class T>
class SegmentTree2 {
 public:
  SegmentTree2(const vector<T>& data, function<T(T, T)> f_, T zero_value = 0)
      : zv(zero_value), f(f_) {
    Initialize(data);
  }
  SegmentTree2(int n, function<T(T, T)> f_, T zero_value = 0)
      : zv(zero_value), f(f_) {
    vector<T> temp(n, zv);
    Initialize(temp);
  }
  T operator[](int i) { return tree[B + i]; }
  T GetEvaluation(int L, int R) {
    if (R <= L) {
      return zv;
    }
    return GetEvaluationHelper(L, R, 0, B, 1);
  }
  void SetVal(int i, T val) {
    tree[B + i] = val;
    for (int j = (B + i) / 2; j >= 1; j /= 2) {
      tree[j] = f(tree[2 * j], tree[2 * j + 1]);
    }
  }

 private:
  vector<T> tree;
  int B;
  T zv;
  function<T(T, T)> f;
  void Initialize(const vector<T>& data) {
    B = 1;
    while (B < data.size()) {
      B *= 2;
    }
    tree = std::move(vector<T>(2 * B, zv));
    copy(data.begin(), data.end(), next(tree.begin(), B));
    for (int i = B - 1; i >= 1; --i) {
      tree[i] = f(tree[2 * i], tree[2 * i + 1]);
    }
  }
  T GetEvaluationHelper(int L, int R, int start, int length, int tree_index) {
    if (L == R) {
      return zv;
    }
    if ((L == start) && (R == start + length)) {
      return tree[tree_index];
    }
    int midpoint = start + length / 2;
    T left_ = zv, right_ = zv;
    if (L <= min(midpoint, R)) {
      left_ = GetEvaluationHelper(L, min(midpoint, R), start, length / 2,
                                  2 * tree_index);
    }
    if (max(midpoint, L) <= R) {
      right_ = GetEvaluationHelper(max(midpoint, L), R, midpoint, length / 2,
                                   2 * tree_index + 1);
    }
    return f(left_, right_);
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cout.precision(17);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  uniform_int_distribution<int> rand_gen(0, modd);
  int test_cases = 1;
  for (int t = (1); t < (1) + (test_cases); ++t) {
    int n;
    cin >> n;
    int k;
    cin >> k;
    vector<int> a;
    for (int i = (0); i < (0) + (n); ++i) {
      int aa;
      cin >> aa;
      a.push_back(aa);
    }
    SegmentTree2<int> seg(
        vector<int>(300001, -1), [](int x, int y) { return max(x, y); }, -1);
    vector<int> solution;
    solution.push_back(1);
    seg.SetVal(a[0], 0);
    for (int i = (1); i < (1) + (n - 1); ++i) {
      int i_max = seg.GetEvaluation(a[i], min(a[i] + k + 1, n + 1));
      int i_min = seg.GetEvaluation(max(0, a[i] - k), a[i] + 1);
      int new_val = 1;
      if (i_max >= 0) {
        new_val = max(new_val, 1 + solution[i_max]);
      }
      if (i_min >= 0) {
        new_val = max(new_val, 1 + solution[i_min]);
      }
      solution.push_back(new_val);
      seg.SetVal(a[i], i);
    }
    int ret = 0;
    for (auto x : solution) {
      ret = max(ret, x);
    }
    cout << ret << endl;
  }
  return 0;
}
