N,K = [int(i) for i in input().split()]
A = []
for i in range(N):
    A.append(int(input()))
maxl = [1]*N

for i in range(N):
    u = A[i]+K
    l = A[i]-K
    for j in range(i+1,N):
        if l <= A[j] <= u:
            maxl[j] = max(maxl[j],maxl[i]+1)
    #print(maxl)
print(max(maxl))
