def solve():
    N,K = map(int,input().split())
    A = [int(input()) for _ in range(N)]
    A_max = max(A)

    dp = [[0] * (A_max+1) for _ in range(N)]
    dp[0][A[0]] = 1

    for i in range(1,N):
        for j in range(A_max+1):
            dp[i][j] = dp[i-1][j]
            mx = 0
            if j == A[i]:
                for k in range(max(0,j-K), min(A_max+1,j+K+1)):
                    mx = max(mx, dp[i-1][k])

                dp[i][j] = max(dp[i][j], mx+1)
    
    ans = 0
    for j in range(A_max):
        ans = max(ans,dp[-1][j])
    
    print(ans)
    
if __name__ == '__main__':
    solve()