#include <bits/stdc++.h>
using namespace std;
long long c[600005] = {0}, tree[1200005] = {0};
long long query(long long ql, long long qr, long long s, long long e,
                long long in) {
  if (ql > e || qr < s || s > e) return -1;
  if (ql <= s && qr >= e) {
    return tree[in];
  }
  int mid = (s + e) / 2;
  return max(query(ql, qr, s, mid, 2 * in + 1),
             query(ql, qr, mid + 1, e, 2 * in + 2));
}
void update(long long s, long long e, long long in, long long key,
            long long up) {
  if (s > e) return;
  if (s == e && s == key) {
    tree[in] = up;
    return;
  } else if (s == e)
    return;
  long long mid = (s + e) / 2;
  update(s, mid, 2 * in + 1, key, up);
  update(mid + 1, e, 2 * in + 2, key, up);
  tree[in] = max(tree[2 * in + 1], tree[2 * in + 2]);
}
int main() {
  long long n, k;
  cin >> n >> k;
  long long a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    long long curr =
        query(max(0ll, a[i] - k), min(300000ll, a[i] + k), 0, 300000, 0);
    ans = max(ans, curr + 1);
    update(0, 300000, 0, a[i], curr + 1);
  }
  cout << ans;
}
