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

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

S=[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[L:(R+1)])+1
    ans=max(tmp,ans)
    S[A]=tmp
    
print(ans)



