from heapq import heappush, heappop


N, K = map(int, input().split())
A = [int(input()) for _ in range(N)]
bigger = [(A[0], 1)]
smaller = [(A[0], 1)]
for a in A[1:]:
    temp = []
    while bigger and abs(a - bigger[0][0]) <= K:
        prev, length = heappop(bigger)
        temp.append((a, length + 1))
    for item in temp:
        heappush(bigger, item)
    temp = []
    while smaller and abs(a - smaller[0][0]) <= K:
        prev, length = heappop(smaller)
        temp.append((a, length + 1))
    for item in temp:
        heappush(smaller, item)
print(max(max(length for _, length in bigger),
          max(length for _, length in smaller)))