def get(lo, hi, idx, qs, qe):
  if hi < qs or qe < lo:
    return 0
  if qs <= lo and hi <= qe:
    return tree[idx]

  mid = (lo + hi) >> 1
  right = (idx + 1) << 1
  return max(get(lo, mid, right - 1, qs, qe), get(mid + 1, hi, right, qs, qe))

def update(lo, hi, idx, ui, val):
  if ui < lo or hi < ui:
    return
  if lo == hi:
    tree[idx] = val
    return

  mid = (lo + hi) >> 1
  right = (idx + 1) << 1
  update(lo, mid, right - 1, ui, val)
  update(mid + 1, hi, right, ui, val)
  tree[idx] = max(tree[right - 1], tree[right])

n, k = map(int, input().split())
a = []
m = 0
for i in range(n):
  a.append(int(input()))
  m = max(m, a[-1])

m = m + 1

tree = [0] * (5 * m)
for i in range(n)[::-1]:
  lo = max(0, a[i] - k)
  hi = min(m - 1, a[i] + k)
  c = get(0, m - 1, 0, lo, hi)
  # print(a[i], '->', c)
  update(0, m - 1, 0, a[i], c + 1)
  # print(tree[0])
  # print(tree[1:3])
  # print(tree[3:7])
  # print(tree[7:15])
  # print(tree[15:31])

print(get(0, m - 1, 0, 0, m - 1))
