san = 300000
N,K = [int(a) for a in input().split()]
L = [0]*300000
for _ in range(N):
    a = int(input())
    M = 0
    if a-K-1<0: l=0
    else: l=a-K-1
    if a+K-1>san-1: r=san
    else: r=a+K
    L[a-1]= max(L[l:r]) +1
    #print(L[:10])
print(max(L))