#include <bits/stdc++.h>
using namespace std;
using pii = pair<long long, long long>;
const long long N = 300001;
long long tree[300300 << 1];
void update(long long idx, long long val) {
  tree[idx += N] = val;
  for (idx >>= 1; idx; idx >>= 1) {
    tree[idx] = max(tree[idx << 1], tree[idx << 1 | 1]);
  }
}
long long solve(long long le, long long ri) {
  long long ret = 0;
  for (le += N, ri += N; le <= ri; le >>= 1, ri >>= 1) {
    if (le & 1) ret = max(ret, tree[le++]);
    if (~ri & 1) ret = max(ret, tree[ri--]);
  }
  return ret;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  long long A[300300], dp[300300];
  for (long long i = 1; i <= n; i++) {
    cin >> A[i];
  }
  dp[0] = 0;
  long long res = dp[1] = 1;
  update(A[1], 1);
  for (long long i = 2; i <= n; i++) {
    long long maxidx = solve(max(A[i] - k, 0LL), min(A[i] + k, N - 1));
    res = max(dp[i] = dp[maxidx] + 1, res);
    dp[i] = max(dp[i], dp[i - 1]);
    update(A[i], i);
  }
  cout << res << '\n';
  return 0;
}
