#include <bits/stdc++.h>
using namespace std;
struct nodeBST {
  int val;
  nodeBST *left, *right;
  int max_sub_seq_len;
  nodeBST(int V, int L = 1) {
    val = V;
    left = right = nullptr;
    max_sub_seq_len = L;
  }
};
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);
    s.push(root);
    while (!s.empty()) {
      auto node = s.top();
      s.pop();
      if (node->val == A[i]) {
        node->max_sub_seq_len = max(node->max_sub_seq_len, tmp_max_sub_seq_len);
        break;
      } else if (node->val > A[i]) {
        if (node->left == nullptr) {
          node->left = new nodeBST(A[i], tmp_max_sub_seq_len);
          break;
        } else
          s.push(node->left);
      } else {
        if (node->right == nullptr) {
          node->right = new nodeBST(A[i], tmp_max_sub_seq_len);
          break;
        } else
          s.push(node->right);
      }
    }
  }
  cout << ans;
}
