input = readlines.map{|x|x.to_i}
n = input[0]
a_list = input.slice(1, n)
max_value = a_list.max
sorted_a_list = a_list.uniq.sort

a_list.each {|a|
    if max_value == a
        p sorted_a_list[n-2]
    elsif
        p max_value
    end
}