a=gets.to_i
c=[]
first = 0
sec = 0
a.times do
  b = gets.chomp.to_i
  c << b
  if a == 1
    first = b
  elsif b > first
    sec = first
    first = b
  elsif b > sec
    sec = b
  end
end
c.each{|t|
  if t != first
    puts first
  else
    puts sec
  end
}