#最長増加部分列問題
N,K=map(int,input().split())
A=[int(input()) for i in range(N)]
dp=[0]*N
 
res=0
for i in range(N):
    dp[i]=1
    for j in range(i):
        if abs(A[j]-A[i])<=K:
            dp[i]=max(dp[i],dp[j]+1)
    res=max(res,dp[i])
print(res)