#include <bits/stdc++.h>
using namespace std;
const long long maxn = 700500;
long long num[maxn] = {0};
long long tree[4 * maxn] = {0};
long long query(long long ql, long long qr, long long l, long long r,
                long long root) {
  if (ql <= l && qr >= r) {
    return tree[root];
  }
  long long mid = (l + r) >> 1;
  long long ans = 0;
  if (ql <= mid) ans = max(ans, query(ql, qr, l, mid, root * 2));
  if (qr > mid) ans = max(ans, query(ql, qr, mid + 1, r, root * 2 + 1));
  return ans;
}
void update(long long pos, long long val, long long l, long long r,
            long long root) {
  if (l == r) {
    tree[root] = val;
    return;
  }
  long long mid = (l + r) >> 1;
  if (pos <= mid) update(pos, val, l, mid, root * 2);
  if (pos > mid) update(pos, val, mid + 1, r, root * 2 + 1);
  tree[root] = max(tree[root * 2], tree[root * 2 + 1]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> num[i];
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    long long temp = query(max(0ll, num[i] - k), num[i] + k, 0, n, 1) + 1;
    ans = max(ans, temp);
    update(num[i], temp, 0, n, 1);
  }
  cout << ans << endl;
}
