#include <bits/stdc++.h>
#pragma optimize("unroll-loops,no-stack-protector")
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long N = 4e5 + 5;
long long tree[N * 4];
long long a[N];
long long n, k;
long long dp[N];
void build(long long node, long long st, long long end) {
  if (st == end) {
    tree[node] = 0;
    return;
  }
  long long mid = (st + end) / 2;
  build(2 * node, st, mid);
  build(2 * node + 1, mid + 1, end);
  tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
void update(long long node, long long st, long long end, long long id,
            long long val) {
  if (st == end) {
    tree[node] += val;
    dp[id] = val;
    return;
  }
  long long mid = (st + end) / 2;
  if (st <= id && id <= mid) {
    update(2 * node, st, mid, id, val);
  } else {
    update(2 * node + 1, mid + 1, end, id, val);
  }
  tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
long long query(long long node, long long st, long long end, long long l,
                long long r) {
  if (st > r || end < l) {
    return 0;
  }
  if (st >= l && end <= r) {
    return tree[node];
  }
  long long mid = (st + end) / 2;
  long long p = query(2 * node, st, mid, l, r);
  long long q = query(2 * node + 1, mid + 1, end, l, r);
  return max(p, q);
}
void solve() {
  cin >> n >> k;
  for (long long i = 0; i < n; i++) cin >> a[i];
  build(1, 0, N);
  memset(dp, 0, sizeof(dp));
  dp[a[0]] = 1;
  update(1, 0, N - 1, a[0], 1);
  long long ans = 1;
  for (long long i = 1; i < n; i++) {
    long long num = a[i];
    long long l = max((long long)0, a[i] - k), r = a[i] + k;
    long long val = query(1, 0, N - 1, l, r);
    update(1, 0, N - 1, a[i], val + 1);
  }
  for (long long i = 0; i < N; i++) {
    ans = max(ans, dp[i]);
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  std::ios::sync_with_stdio(false);
  long long te = 1;
  while (te--) {
    solve();
  }
}
