n,k = map(int, input().split())

b = [0] * (n+1)
ans = 0

for i in range(n):
  a = int(input())
  m = b[a] + 1
  s = max(1, a-k)
  u = min(n+1, a+k+1)
  for j in range(s, u):
    b[j] = max(b[j],m)
  if m > ans:
    ans = m

print(ans)