#k = int(input())
n,k = map(int, input().split())
#a = list(map(int, input().split()))
cnt = [0]*(n+1)

for _ in range(n):
    a = int(input())
    cnt[a] = max(cnt[max(0,a-k):min(n,a+k+1)])+1

print(max(cnt))