n, k = map(int, input().split())
ans = 0
dp = [0] * 3*10**5
for i in range(n):
    ai = int(input())
    longest = 0
    for aj in range(max(0, ai-k), min(ai+k+1, n)):
        longest = max(longest, dp[aj])
    dp[ai] = max(dp[ai], longest + 1)
    ans = max(ans, dp[ai])
print(ans)
