N = gets.chomp.to_i
a = Array.new(N)
for i in 0...N do
    a[i] = gets.chomp.to_i
end

max_n = a[0]
max_i = 0
second = 0

for i in 1...N do
    if a[i] > max_n
        second = max_n
        max_n = a[i]
        max_i = i
    elsif a[i] > second
        second = a[i]
    end
end

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