N , K = map(int, input().split())
An = [int(input()) for _ in range(N)]
dp = [1]*N

for i in range(N):
    max_value = 0
    Ai = An[i]
    for j in range(i):
        Aj = An[j]
        if abs(Ai - Aj) <= K:
            max_value = max(max_value, dp[j])
    dp[i]+=max_value

print(max(dp))
