# For taking integer inputs.
def inp():
    return(int(input()))


N = inp()
A = []
i1, i2 = 0, 0

for i in range(N):
    A.append(inp())
    if A[i] > A[i1]:
        i1 = i


for i in range(N):
    if A[i] > A[i2] and i != i1:
        i2 = i
for i in range(N):
    if i != i1:
        print(A[i1])
    else:
        print(A[i2])
