N = gets.chomp.to_i
as = [] 
N.times { as.push(gets.chomp.to_i) }

first = -1
second = -1
N.times do |i|
  if first < as[i]
    second = first
    first = as[i]
  elsif second < as[i]
    second = as[i]
  end
end

as.map! { |a| a == first ? second : first }

puts as.join("\n")
