from collections import deque
N,K = map(int,input().split())
A = [int(input()) for _ in range(N)]
G = {i:[0,[]] for i in range(N)}
for i in range(N):
    for j in range(i+1,N):
        if 0<=A[j]-A[i]<=K:
            G[i][1].append(j)
            G[j][0] += 1
            break
for i in range(N):
    for j in range(i+1,N):
        if 0<A[i]-A[j]<=K:
            G[i][1].append(j)
            G[j][0] += 1
            break
S = []
for i in range(N):
    if G[i][0]==0:
        S.append(i)
dist = [-1 for _ in range(N)]
for i in S:
    que = deque([(i,0)])
    dist[i] = 0
    while que:
        x,d = que.popleft()
        for y in G[x][1]:
            if dist[y]<d+1:
                dist[y]=d+1
                que.append((y,d+1))
dmax = max(dist)
print(dmax+1)