require 'pp'
require 'set'

n = gets.chomp!.to_i
a_n = []
a_n2 = SortedSet.new
max1 = -1
max2 = -1
n.times do |i|
    a = gets.chomp!.to_i
    a_n << a
    a_n2 << a
end

a_n2.reverse_each.with_index(0) do |x, i|
    if i == 0
        max1 = x
    elsif i == 1
        max2 = x
    else
        break
    end
end

if max2 == -1
    max2 = max1
end

a_n.each do |num, cnt|
    if max1 == num
        puts max2
    else
        puts max1
    end
end
