n = gets.chomp.to_i

a = []
sort = []

for i in 1..n do
    line = gets.chomp.to_i
    a.push(line)
    sort.push(line)
end

sort.sort!.reverse!
max1 = sort[0]
max2 = sort[1]

for i in 1..n do 
    if a[i-1] == max1
        puts max2
    else
        puts max1
    end
end