n,k=map(int,input().split())
b=[int(input()) for _ in range(n)]
dp=[[0]*(max(b)+1) for _ in range(n+1)]
a=b[0]
dp[1][a]=1
c=max(b)
for i in range(2,n+1):
    a=b[i-1]
    dp[i][a]=max(dp[i][a],1)
    for j in range(max(a-k,0),min(a+k,c+1)):
        if dp[i-1][j]!=0:
            dp[i][a-(a-j)]=max(dp[i-1][a-(a-j)],dp[i-1][j]+1)
    for j in range(c+1):
        dp[i][j]=max(dp[i][j],dp[i-1][j])
print(max(dp[-1]))
