N,K = map(int,input().split())
A = [int(input()) for _ in range(N)]
dp2 = [0] * N
for i in range(N):
    tmax = 0
    for j in range(i+1):
        if abs(A[i]-A[j]) <= K:
            tmax = max(tmax,dp2[j]+1)
    dp2[i] = tmax  

print(max(dp2))