#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1 << 30;
const ll INFll = 1LL << 62;
const int mod = int(1e9) + 7;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using ld = long double;
using V = vector<int>;
using Vl = vector<ll>;
using VV = vector<vector<int>>;
using VVl = vector<vector<ll>>;
int MAX_N = 300001;
VVl bit(MAX_N, Vl());
void add(ll i, ll a, ll w) {
  for (ll x = a; x <= MAX_N; x += x & -x) bit[x][i] += w;
}
ll sum(ll i, ll a) {
  ll ret = 0;
  for (int x = a; x > 0; x -= x & -x) ret += bit[x][i];
  return ret;
}
int main() {
  ll n, k;
  cin >> n >> k;
  Vl a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  ll mm = 0;
  Vl tp(MAX_N, 0);
  for (ll i = 0; i < n; ++i) {
    for (ll j = mm; j >= 0; --j) {
      if (j == 0) {
        if (bit.size() == j) {
          bit.push_back(tp);
        }
        if (a[i] + k + 1 <= MAX_N) {
          add(j + 1, a[i] + k + 1, -1);
        }
        if (a[i] - k >= 0) {
          add(j + 1, a[i] - k, 1);
        }
        mm = max(mm, j + 1);
      } else {
        if (sum(j, a[i])) {
          if (bit.size() == j) {
            bit.push_back(tp);
          }
          if (a[i] + k + 1 <= MAX_N) {
            add(j + 1, a[i] + k + 1, -1);
          }
          if (a[i] - k >= 0) {
            add(j + 1, a[i] - k, 1);
          }
          mm = max(mm, j + 1);
        }
      }
    }
  }
  cout << mm << endl;
}
