#include <bits/stdc++.h>
using vi = std::vector<long long int>;
using vvi = std::vector<vi>;
using pii = std::pair<long long int, long long int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
using namespace std;
const long long int N = 6e6 + 10;
const long long int inf = 1e18 + 10;
const long double Pi = 3.14159265;
long long int n, k, a[N], ans = 1, z = 1;
map<long long int, long long int> t;
long long int sum(long long int l, long long int r, long long int v = 1,
                  long long int tl = 0, long long int tr = N) {
  if (l > r) return 0;
  if (l == tl && r == tr) return t[v];
  long long int tm = (tl + tr) / 2;
  return max(sum(l, min(r, tm), v * 2, tl, tm),
             sum(max(l, tm + 1), r, v * 2 + 1, tm + 1, tr));
}
void update(long long int pos, long long int new_val, long long int v = 1,
            long long int tl = 0, long long int tr = N) {
  if (tl == tr) {
    t[v] = new_val;
  } else {
    long long int tm = (tl + tr) / 2;
    if (pos <= tm)
      update(pos, new_val, v * 2, tl, tm);
    else
      update(pos, new_val, v * 2 + 1, tm + 1, tr);
    t[v] = max(t[v * 2], t[v * 2 + 1]);
  }
}
void solve() {
  cin >> n >> k;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
    z = sum(max(a[i] - k, 0LL), min(a[i] + k, N)) + 1;
    update(a[i], max(z, 1LL));
    ans = max(ans, z);
  }
  cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
  long long int xx = 0;
  long long int t;
  cin >> t;
  while (t--) {
    ;
    solve();
    cout << endl;
  }
  return 0;
}
