#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  vector<vector<ll> > edge_f(n, vector<ll>(0));
  vector<vector<ll> > edge_b(n, vector<ll>(0));
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int cnt = 0;
      if (abs(a[i] - a[j]) <= k) {
        edge_f[i].emplace_back(j);
        cnt++;
        if (cnt > 1000) break;
      }
    }
  }
  reverse((a).begin(), (a).end());
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int cnt = 0;
      if (abs(a[i] - a[j]) <= k) {
        edge_b[i].emplace_back(j);
        cnt++;
        if (cnt > 1000) break;
      }
    }
  }
  vector<ll> dist_f(n, 1), dist_b(n, 1);
  for (int i = 0; i < n; ++i) {
    for (const auto& v : edge_f[i]) {
      dist_f[v] = max(dist_f[v], dist_f[i] + 1LL);
    }
  }
  for (int i = 0; i < n; ++i) {
    for (const auto& v : edge_b[i]) {
      dist_b[v] = max(dist_b[v], dist_b[i] + 1LL);
    }
  }
  cout << max(*max_element((dist_f).begin(), (dist_f).end()),
              *max_element((dist_b).begin(), (dist_b).end()));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  solve();
  return 0;
}
