n, k = map(lambda x: int(x), input().split())

list_a = []
max_a = 0
for _ in range(n):
    a = int(input())
    list_a.append(a)
    max_a = max(max_a, a)

# 意味合い的にはNoneの方がより正しいが、0で問題ない
dp = [0] * max_a

for a in list_a:
    i_latest_number = a - 1
    updated_length = 0
    for i in range(max(0, i_latest_number-k), min(max_a, i_latest_number+k+1)):
        updated_length = max(updated_length, dp[i]+1)
    dp[i_latest_number] = updated_length
#     print(dp)
print(max(dp))