N = io.read("*n")
A = {}
for i = 1, N do
    A[i] = io.read("*n")
end
A_max = 0
for i = 1, N do
    A_max = math.max(A_max, A[i])
end
A_max2 = 0
for i = 1, N do
    if A[i] ~= A_max then
        A_max2 = math.max(A_max2, A[i])
    end
end
for i = 1, N do
    if A[i] ~= A_max then
        print(A_max)
    else
        print(A_max2)
    end
end