n = gets.to_i
as = []

max = secondary = 0
n.times do
  a = gets.to_i

  if a > max
    max = a
  elsif a > secondary
    secondary = a
  end

  as.push(a)
end

as.each do |a|
  puts a == max ? secondary : max
end
