N,K = map(int,input().split())
l = list()
for _ in range(N):
  l.append(int(input()))
llen = [0]*N
for i in reversed(range(N)):
  mlen = [x[1] for x in zip(l[i+1:],llen[i+1:]) if -K <= x[0]-l[i] <= K]
  llen[i] = max(mlen)+1 if len(mlen) else 1
print(max(llen))