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