n,k = map(int , raw_input().split())
ais = [int(raw_input()) for _ in range(n)]
h = [0 for oo in range(300001)]
for ai in ais:
    h[ai]  = 1 + max([h[v] for v in range(ai-k, ai + k +1) if 0<=v<len(h)] or [0])
print max(h)