N, K = map(int, input().split())
A = [int(input()) for _ in range(N)]
# print(N,K)
# print(A)
ans = 0
dp = [0] * (N)
for i in range(N):
    longest = 0
    for j in range(max(0, i-K), min(i+K+1, N)): # j:[i-K,i+K]
        if abs(A[j] - A[i]) <= K: # |aj-ai|<=K
            longest = max(longest, dp[j])
    dp[i] = max(dp[i], longest + 1)
    ans = max(ans, dp[i])
# print(dp)
# print(max(dp))
print(ans)
