line = gets.chomp.split(" ").map(&:to_i)
n = line[0]

max = [0, 0]
max_pos = [0, 0]
num_arr = []
n.times do |i|
    number = gets.chomp.to_i
    num_arr.push(number)
    if max[0] < number
        max[1] = max[0]
        max_pos[1] = max_pos[0]
        max[0] = number
        max_pos[0] = i
    elsif max[1] < number
        max[1] = number
        max_pos[1] = i
    end
end

n.times do |i|
    if max_pos[0] == i
        puts max[1]
    else
        puts max[0]
    end
end
