function solve()
    N,K=parse.(Int,split(readline()))
    D=zeros(Int,300_001)
    for _ in 1:N
        Ai=parse(Int,readline())+1
        mx=0
        for i=Ai-K:Ai+K
            if 1<=i<=N
                if D[i]>mx
                    mx=D[i]
                end
            end
        end
        D[Ai]=mx+1
        #println(D)
    end
    println(maximum(D))
end
solve()