N, K = map(int, input().split())
A = [0 for _ in range(N)]
for i in range(N):
    A[i] = int(input())
    
dp = [1 for _ in range(N)]
for i in range(N-1):
    for j in range(i+1, N):
        if abs(A[i] - A[j]) <= K:
            dp[j] = max(dp[j], dp[i]+1)
print(max(dp))
