N = gets()
ary = []
N.to_i.times do |_|
  ary << gets()
end
ret = []

ary.each_with_index do |e, i|
  r1 = ary[0, i].max
  r2 = ary[i+1, 200000].max
  if r1.nil?
    ret << r2
  elsif r2.nil?
    ret << r1
  else
    if r1 < r2
      ret << r2
    else
      ret << r1
    end
  end
end  

ret.each do |e|
  puts e
end               

