#include <bits/stdc++.h>
using namespace std;
long long i, j, k, m, n, p = 1, v, a[1050000], l[1050000], r[1050000];
long long M(long long x, long long y, long long d) {
  if (x <= l[d] && r[d] <= y) return a[d];
  if (r[d] < x || y < l[d]) return 0;
  return max(M(x, y, d << 1), M(x, y, (d << 1) + 1));
}
void REP(int i, long long k) {
  for (a[i += p] = k; i >>= 1;) {
    a[i] = max(a[i << 1], a[(i << 1) + 1]);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (p = 524288; i < p; i++) l[p + i] = r[p + i] = i;
  for (i = p; --i;) {
    l[i] = l[i << 1];
    r[i] = r[(i << 1) + 1];
  }
  for (i = 0; i++ < n;) {
    cin >> v;
    REP(v, M(max(1LL, v - k), min(300000LL, v + k), 1) + 1);
    m = max(m, a[v + p]);
  }
  cout << m;
}
