#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4 * atan(1);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
const int MAX_N = 1 << 20;
int N, n, k;
int A[MAX_N];
int dat[2 * MAX_N - 1];
void init(int n_) {
  n = 1;
  while (n < n_) n *= 2;
}
void update(int k, int a) {
  k += n - 1;
  dat[k] = max(dat[k], a);
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
  }
}
int query(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l) return 0;
  if (a <= l && r <= b)
    return dat[k];
  else
    return max(query(a, b, k * 2 + 1, l, (l + r) / 2),
               query(a, b, k * 2 + 2, (l + r) / 2, r));
}
void solve() {
  init(n);
  int res = 1;
  for (int i = 0; i < N; ++i) {
    const int mi = max(0, A[i] - k);
    const int mx = min(2 * MAX_N - 2, A[i] + k);
    int best = query(mi, mx + 1, 0, 0, n) + 1;
    res = max(res, best);
    update(A[i], best);
  }
  cout << res << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  N = n;
  for (int i = 0; i < n; ++i) cin >> A[i];
  solve();
  return 0;
}
