from collections import deque
N,K = map(int,input().split())
A = [int(input()) for _ in range(N)]
G = {i:[0,[-1,-1]] for i in range(N)}
for i in range(N):
    for j in range(i+1,N):
        if A[j]>=A[i] and A[j]-A[i]<=K and G[i][1][1]<0:
            G[i][1][1]=j
            G[j][0] += 1
        if A[j]<A[i] and A[i]-A[j]<=K and G[i][1][0]<0:
            G[i][1][0]=j
            G[j][0] += 1
        if G[i][1][0]>=0 and G[i][1][1]>=0: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()
        y = G[x][1][0]
        if y>=0 and dist[y]<d+1:
            dist[y]=d+1
            que.append((y,d+1))
        y = G[x][1][1]
        if y>=0 and dist[y]<d+1:
            dist[y]=d+1
            que.append((y,d+1))
dmax = max(dist)
print(dmax+1)