#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5, total = 2e6;
int a[MAXN], segTree[total], ans = 0;
int rangeQuery(int qlow, int qhigh, int low, int high, int pos) {
  if (qlow <= low && high <= qhigh) {
    return segTree[pos];
  }
  if (qlow > high || low > qhigh) {
    return 0;
  }
  int mid = (low + high) / 2;
  int val1 = rangeQuery(qlow, qhigh, low, mid, 2 * pos + 1);
  int val2 = rangeQuery(qlow, qhigh, mid + 1, high, 2 * pos + 2);
  return max(val1, val2);
}
void update(int val, int idx, int low, int high, int pos) {
  if (low == high) {
    segTree[pos] = max(segTree[pos], val);
    return;
  }
  int mid = (low + high) / 2;
  if (idx <= mid) {
    update(val, idx, low, mid, 2 * pos + 1);
  } else {
    update(val, idx, mid + 1, high, 2 * pos + 2);
  }
  segTree[pos] = max(segTree[2 * pos + 1], segTree[2 * pos + 2]);
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  memset(segTree, 0, sizeof(segTree));
  for (int i = 0; i < n; i++) {
    int c = max(a[i] - k, 0);
    int d = min(a[i] + k, n - 1);
    int best = rangeQuery(c, d, 0, n - 1, 0);
    update(best + 1, a[i], 0, n - 1, 0);
    ans = max(best + 1, ans);
  }
  cout << ans << endl;
}
