N, K = [int(n) for n in input().split(" ")]
A = []
for _ in range(N):
    A.append(int(input()))


D = [-1 for _ in range(300001)]
DD = []

ANS = -1

for n in range(N):
    maxd = -1
    for s in range(A[n] - K, A[n] + K + 1):
        if s < 0 or s > 300001:
            continue
        d = D[s] + 1
        if maxd <= d:
            maxd = d
    if maxd <= 0:
        maxd = 1
    D[A[n]] = maxd
    DD.append(maxd)

    if ANS <= maxd:
        ANS = maxd

print(ANS)


