#include <bits/stdc++.h>
using namespace std;
const long long N = 525000, L = 19;
long long b[N], a[N];
vector<vector<long long>> v;
long long n, k;
void set1(long long in, long long x);
long long sum(long long l, long long r, long long x, long long y);
void set1(long long in, long long x) {
  long long j = in;
  for (long long i = 0; i <= L; i++) {
    v[i][in] = max({sum(j / pow(2ll, i) * pow(2ll, i), j, 0, n),
                    sum(j + 1, j / pow(2ll, i) * pow(2ll, i) + j, 0, n), x});
    in /= 2;
  }
  a[j] = x;
}
long long sum(long long l, long long r, long long x, long long y) {
  if (l > r) return 0ll;
  if (l == r) return 0ll;
  if (l == r - 1) {
    return a[l];
  }
  long long mid = (x + y) / 2, dis = r - l;
  if (l == x && r == y) {
    long long ans = -1;
    while (dis) {
      dis /= 2;
      ans++;
    }
    return v[ans][x / pow(2, ans)];
  }
  if (l > x || r < y) {
    return max(sum(l, min(mid, r), x, mid), sum(max(l, mid), r, mid, y));
  }
  return 0;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  long long n2 = n;
  for (long long i = 0; i < n; i++) cin >> b[i];
  for (long long i = n; i < pow(2, L); i++) {
    a[i] = 0ll;
  }
  n = pow(2, L);
  v.push_back({});
  for (long long i = 0; i < n; i++) {
    v[0].push_back(a[i]);
  }
  for (long long i = 1; i <= L; i++) {
    v.push_back({});
    for (long long j = 0; j < v[i - 1].size(); j += 2) {
      v[i].push_back(max(v[i - 1][j], v[i - 1][j + 1]));
    }
  }
  for (long long i = 0; i < n2; i++) {
    long long l = max(0ll, b[i] - k);
    long long r = min(N, b[i] + k);
    set1(i, sum(l, r + 1, 0, n) + 1);
  }
  cout << *max_element(a, a + n);
}
