N = gets.chomp.to_i

a = 0
max_n = 0
max_i = 0
second = 0

for i in 1...N do
    a = gets.chomp.to_i
    if a > max_n
        second = max_n
        max_n = a
        max_i = i
    elsif a > second
        second = a
    end
end

for i in 0...N do
    if i == max_i
        puts second
    else
        puts max_n
    end
end