#include <bits/stdc++.h>
using namespace std;
int arr[300000];
int maxlen[300000];
const int N = 300000;
int t[4 * N + 1];
void buildTree(int* tree, int index, int s, int e) {
  if (s > e) return;
  if (s == e) {
    tree[index] = 0;
    return;
  }
  int m = (s + e) / 2;
  buildTree(tree, 2 * index, s, m);
  buildTree(tree, 2 * index + 1, m + 1, e);
  tree[index] = max(tree[2 * index], tree[2 * index + 1]);
  return;
}
int query(int* tree, int index, int s, int e, int qs, int qe) {
  if (qs > e || s > qe) return INT_MIN;
  if (s >= qs && e <= qe) return tree[index];
  int m = (s + e) / 2;
  int left_ans = query(tree, 2 * index, s, m, qs, qe);
  int right_ans = query(tree, 2 * index + 1, m + 1, e, qs, qe);
  return max(left_ans, right_ans);
}
void updateNode(int* tree, int index, int s, int e, int pos, int val) {
  if (pos < s || pos > e) return;
  if (s == e) {
    tree[index] = val;
    return;
  }
  int m = (s + e) / 2;
  updateNode(tree, 2 * index, s, m, pos, val);
  updateNode(tree, 2 * index + 1, m + 1, e, pos, val);
  tree[index] = max(tree[2 * index], tree[2 * index + 1]);
  return;
}
int main() {
  int result = 0;
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int s = 0, e = n - 1;
  buildTree(t, 1, 0, n - 1);
  for (int i = 0; i < n; i++) {
    int a = arr[i];
    int maxim = query(t, 1, s, e, a - k, a + k + 1);
    updateNode(t, 1, s, e, a, maxim + 1);
    maxlen[i] = maxim + 1;
    result = max(result, maxlen[i]);
  }
  cout << result << endl;
}
