#include <bits/stdc++.h>
using namespace std;
struct _ {
  ios_base::Init i;
  _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); }
} _;
const long long maxn = 3e5;
long long n, k;
vector<long long> a(maxn + 1, 0);
vector<long long> dp(maxn + 1, 0);
vector<long long> tree(2 * maxn + 1, 0);
long long merge(long long a, long long b) { return max(a, b); }
void update(long long ui, long long uv, long long l, long long r,
            long long ind) {
  if (l == r) {
    if (l == ui) {
      tree[ind] = max(tree[ind], uv);
    }
    return;
  }
  long long mid((l + r) >> 1);
  if (ui <= mid)
    update(ui, uv, l, mid, 2 * ind);
  else
    update(ui, uv, mid + 1, r, 2 * ind + 1);
  tree[ind] = merge(tree[2 * ind], tree[2 * ind + 1]);
}
long long query(long long ql, long long qr, long long l, long long r,
                long long ind) {
  if (qr < l or r < ql) return 0;
  if (ql <= l and r <= qr) return tree[ind];
  long long mid((l + r) >> 1);
  return merge(query(ql, qr, l, mid, 2 * ind),
               query(ql, qr, mid + 1, r, 2 * ind + 1));
}
int main() {
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= n; i++) {
    dp[i] = 1 + query(a[i] - k, a[i] + k, 1, maxn, 1);
    update(a[i], dp[i], 1, maxn, 1);
  }
  cout << *max_element(dp.begin(), dp.end());
  return 0;
}
