n = gets.chomp.to_i

a = []
max1 = 0
max2 = 0

for i in 1..n do
    line = gets.chomp.to_i
    a.push(line)
    if max1 <= line
        max2 = max1
        max1 = line
    elsif max2 <= line
        max2 = line
    end
end

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