from collections import deque

N,K = list(map(int,input().split()))
A = [int(input()) for i in range(N)]
if N == 1:
    print(1)
    exit()

lst = [-1]*(N+1)
queue = deque()
queue.append((A[0],1,1))
ans = 0
while queue:
    # print(queue)
    r,size,i = queue.popleft()
    if i == N:
        ans = max(ans,size)
        continue
    if lst[r] <= size:
        if abs(r-A[i]) <= K:
            queue.append((A[i],size+1,i+1))
        else:
            queue.append((r,size,i+1))
        lst[r] = size
print(ans)