N,K = (int(T) for T in input().split())
A = [int(input()) for TN in range(0,N)]
Table = [0]*300002
for TN in range(0,N):
    Table[max(A[TN]-K,0)] += 1
    Table[min(A[TN]+K,300001)] -= 1
for TN in range(0,300001):
    Table[TN+1] += Table[TN]
print(max(Table))