import types
import bisect
N , K = map(int,input().split())
A = [int(input()) for _ in range(N)]
Ad = set(A)
Ad = list(Ad)
length = len(Ad)
Ad.sort()
d = [0 for k in range(max(A)+1)]
candidate = [[] for i in range(length)]
Anum = [0]*(max(A)+1)
for i in range(length):
  j = Ad[i]
  Anum[j] = i
for i in range(length):
  ma = Ad[i]
  for j in range(i):
    target = Ad[i-j-1]
    if abs(target - ma) <= K:
      candidate[i].append(j)
    else:
      break
  for j in range(length - i):
    target = Ad[j+i]
    if abs(target - ma) <= K:
      candidate[i].append(j)
    else:
      break
for i in range(N):
  a = A[i]
  p = Anum[a]
  for j in candidate[p]:
    d[a] = max(d[a],d[Ad[j]]+1)
print(max(d))  