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

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

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

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

    C=0
    for j in range(D):
        if L>R: break

        if L==R:
            C=max(C,S[j][L])
            break 

        if R%2==0:
            C=max(C,S[j][R])
            R=R//2-1
        else:
            R=R//2

        if L%2==1:
            C=max(C,S[j][L])
            L=L//2+1
        else:
            L=L//2
        
    tmp=C+1
    ans=max(tmp,ans)

    S[0][A]=tmp
    for j in range(1,D):
        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)



