#include <bits/stdc++.h>
using namespace std;
struct nodeBST {
  int val;
  nodeBST *left, *right;
  int height;
  int max_sub_seq_len;
  nodeBST(int V, int L = 1) {
    val = V;
    left = right = nullptr;
    max_sub_seq_len = L;
    height = 1;
  }
};
int nodeBSTheight(nodeBST *node) {
  if (node == nullptr) return 0;
  return node->height;
}
nodeBST *rightRotate(nodeBST *y) {
  nodeBST *x = y->left;
  nodeBST *T2 = x->right;
  x->right = y;
  y->left = T2;
  y->height = max(nodeBSTheight(y->left), nodeBSTheight(y->right)) + 1;
  x->height = max(nodeBSTheight(x->left), nodeBSTheight(x->right)) + 1;
  return x;
}
nodeBST *leftRotate(nodeBST *x) {
  nodeBST *y = x->right;
  nodeBST *T2 = y->left;
  y->left = x;
  x->right = T2;
  x->height = max(nodeBSTheight(x->left), nodeBSTheight(x->right)) + 1;
  y->height = max(nodeBSTheight(y->left), nodeBSTheight(y->right)) + 1;
  return y;
}
int getBalance(nodeBST *N) {
  if (N == nullptr) return 0;
  return nodeBSTheight(N->left) - nodeBSTheight(N->right);
}
nodeBST *insert(nodeBST *node, int key, int L = 1) {
  if (node == nullptr) return (new nodeBST(key, L));
  if (key < node->val)
    node->left = insert(node->left, key, L);
  else if (key > node->val)
    node->right = insert(node->right, key, L);
  else {
    node->max_sub_seq_len = max(node->max_sub_seq_len, L);
    return node;
  }
  node->height = 1 + max(nodeBSTheight(node->left), nodeBSTheight(node->right));
  int balance = getBalance(node);
  if (balance > 1 && key < node->left->val) return rightRotate(node);
  if (balance < -1 && key > node->right->val) return leftRotate(node);
  if (balance > 1 && key > node->left->val) {
    node->left = leftRotate(node->left);
    return rightRotate(node);
  }
  if (balance < -1 && key < node->right->val) {
    node->right = rightRotate(node->right);
    return leftRotate(node);
  }
  return node;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (auto &i : A) cin >> i;
  nodeBST *root = new nodeBST(A[0]);
  int ans = 1;
  for (int i = 1; i < N; i++) {
    int m = max(0, A[i] - K), M = min(300000, A[i] + K);
    stack<nodeBST *> s;
    s.push(root);
    int tmp_max_sub_seq_len = 1;
    while (!s.empty()) {
      auto node = s.top();
      s.pop();
      if (node->val <= m) {
        if (node->val == m)
          tmp_max_sub_seq_len =
              max(tmp_max_sub_seq_len, node->max_sub_seq_len + 1);
        if (node->right != nullptr) s.push(node->right);
      } else if (node->val >= M) {
        if (node->val == M)
          tmp_max_sub_seq_len =
              max(tmp_max_sub_seq_len, node->max_sub_seq_len + 1);
        if (node->left != nullptr) s.push(node->left);
      } else {
        tmp_max_sub_seq_len =
            max(tmp_max_sub_seq_len, node->max_sub_seq_len + 1);
        if (node->right != nullptr) s.push(node->right);
        if (node->left != nullptr) s.push(node->left);
      }
    }
    ans = max(ans, tmp_max_sub_seq_len);
    root = insert(root, A[i], tmp_max_sub_seq_len);
  }
  cout << ans;
}
