#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const double PI = acos(-1.0);
using namespace std;
const double EPS = 1e-9;
const int N = 300000 + 9;
int n, k, a[N], val[N * 5];
void up(int s, int e, int p, int idx, int v) {
  if (s == e) {
    val[p] = max(val[p], v);
    return;
  }
  int mid = (s + e) / 2;
  if (idx <= mid)
    up(s, mid, p * 2, idx, v);
  else
    up(mid + 1, e, p * 2 + 1, idx, v);
  val[p] = max(val[p * 2], val[p * 2 + 1]);
}
int get(int s, int e, int p, int l, int r) {
  if (s >= l && e <= r) return val[p];
  int mid = (s + e) / 2;
  if (r <= mid)
    return get(s, mid, p * 2, l, r);
  else if (l > mid)
    return get(mid + 1, e, p * 2 + 1, l, r);
  else
    return max(get(s, mid, p * 2, l, r), get(mid + 1, e, p * 2 + 1, l, r));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int mx = get(1, n, 1, max(1, a[i] - k), min(n, a[i] + k));
    ans = max(ans, mx + 1);
    up(1, n, 1, a[i], mx + 1);
  }
  cout << ans << endl;
  return 0;
}
