n = gets.to_i
list = []
top2 = [0, 0]
n.times {
    a = gets.to_i
    if top2[0] < a
        top2[1] = top2[1]
        top2[0] = a
    elsif top2[1] < a
        top2[1] = a
    end
    
    list.push(a)
}

list.each {|a|
    puts a == top2[0] ? top2[1] : top2[0]
}