# -*- coding: utf-8 -*-

N,K=map(int,input().split())

S=[]
for i in range(19):
    S.append([0]*2**i)
S.append([0]*300010)

ans=0
for i in range(N):
    A=int(input())
    R=min(A+K,300000)
    L=max(A-K,0)

    #tmp=max(S[19][L:(R+1)])+1
    M=[]
    j=19
    while(1):
        if L==R:
            M.append(S[j][L])
            break

        if R%2==0:
            M.append(S[j][R])
            R=R//2-1
        else:
            R=R//2

        if L%2==1:
            M.append(S[j][L])
            L=L//2+1
        else:
            L=L//2

        j-=1
        if j<0: break
        
    tmp=max(M)+1
    ans=max(tmp,ans)

    #S[A]=tmp
    S[19][A]=tmp
    for j in range(18,-1,-1):
        a=A//2
        if A%2==0:
            B=A+1
        else:
            B=A-1
        S[j][a]=max(S[j+1][A],S[j+1][B])
        A=a
    
    
print(ans)



