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


D = []

ANS = -1

for n in range(N):
    maxd = -1
    for j in range(n - 1, -1, -1):
        if j + 1 <= maxd - 1:
            break
        if A[j] >= A[n] - K and A[j] <= A[n] + K:
            d = D[j] + 1
            if maxd <= d:
                maxd = d
    if maxd == -1:
        maxd = 1
    D.append(maxd)

    if ANS <= maxd:
        ANS = maxd

print(ANS)

