from collections import defaultdict


N, K = map(int, input().split())
A = [int(input()) for _ in range(N)]
dp = defaultdict(int)
for a in A:
    for prev in list(dp.keys()):
        if abs(prev - a) <= K:
            dp[a] = max(dp[prev] + 1, dp[a])
    dp[a] = max(1, dp[a])
print(max(dp.values()))