#include <bits/stdc++.h>
using namespace std;
template <typename T>
class Segment_tree {
 public:
  Segment_tree(int _n) {
    n = _n;
    tree.resize(2 * n, 0);
  }
  T combine(T lchild, T rchild) { return max(lchild, rchild); }
  void update(int idx, T val) {
    for (tree[idx += n] = val, idx /= 2; idx >= 1; idx /= 2) {
      tree[idx] = combine(tree[idx << 1], tree[idx << 1 | 1]);
    }
  }
  T query(int l, int r) {
    T ans = 0;
    for (l += n, r += n; l <= r; l /= 2, r /= 2) {
      if (l & 1) {
        ans = combine(ans, tree[l++]);
      }
      if (!(r & 1)) {
        ans = combine(ans, tree[r--]);
      }
    }
    return ans;
  }

 private:
  int n;
  vector<T> tree;
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int sz = 1 << 19;
  Segment_tree<int> dp(1 << 19);
  dp.update(a[0], 1);
  for (int i = 1; i < n; ++i) {
    dp.update(a[i], 1 + dp.query(a[i] - k, a[i] + k));
  }
  cout << dp.query(0, sz - 1) << endl;
}
