N,K=map(int,input().split())
A=[]
for i in range(N):
    a=int(input())
    A.append(a)
dp=[0]*N
dp[0]=1
Ma=max(A)
B=[0]*(Ma+1)
B[A[0]]=1
for i in range(1,N):
    a=A[i]
    Max=max(B[max(0,a-K):min(Ma+1,a+K+1)])
    dp[i]=Max+1
    B[a]=Max+1
print(max(B))