#include <bits/stdc++.h>
using namespace std;
class segment {
 public:
  int n;
  vector<int> tree;
  segment(int n) {
    this->n = n;
    tree.resize(4 * n);
  }
  void update(int idx, int val, int l, int r, int v) {
    if (r - l == 1) {
      tree[v] = max(tree[v], val);
      return;
    }
    int mid = (l + r) / 2;
    if (idx < mid) {
      update(idx, val, l, mid, 2 * v);
    } else {
      update(idx, val, mid, r, 2 * v + 1);
    }
    tree[v] = max(tree[2 * v], tree[2 * v + 1]);
  }
  void update(int idx, int val) { update(idx, val, 0, n, 1); }
  int mx(int p, int q, int l, int r, int v) {
    if (q <= l || p >= r) {
      return INT_MIN;
    }
    if (p <= l && r <= q) {
      return tree[v];
    }
    int mid = (l + r) / 2;
    int x = mx(p, q, l, mid, 2 * v);
    int y = mx(p, q, mid, r, 2 * v + 1);
    return max(x, y);
  }
  int mx(int p, int q) { return mx(p, q, 0, n, 1); }
};
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  const int MAX_A = 300 * 1000;
  segment tree(MAX_A + 1);
  vector<int> dp(n);
  dp[n - 1] = 1;
  tree.update(a[n - 1], 1);
  for (int i = n - 2; i >= 0; i--) {
    dp[i] = max(dp[i + 1],
                tree.mx(max(0, a[i] - k), min(MAX_A + 1, a[i] + k + 1)) + 1);
    tree.update(a[i], dp[i]);
  }
  cout << dp[0] << '\n';
  return 0;
}
