n,k=map(int,input().split())

A=[]
for i in range(n):
    A.append(int(input()))



dp=[0 for i in range(n)]

dp[0]=1

for i in range(1,n):
    for j in range(i):
        if -k<=(A[j]-A[i])<=k:
            dp[i]=max(dp[i],dp[j]+1)

print(max(dp))
