n, k = map(int, input().split())
a = [0]
for _ in range(n):
    a.append(int(input()))

table = [0]*(n+1)
dp = [0]*(n+1)

for i in range(1, n+1):
    down = a[i]-k
    up = a[i]+k
    if a[i]-k < 1:
        down = 1
    if a[i]+k > n:
        up = n
    dp[i] = max(table[down:up+1])+1
    table[a[i]] = dp[i]

print(dp[-1])