n = gets.to_i
as = []
max = 0
n.times do
  a = gets.to_i
  as.push a
  max = a if max < a
end

as.each_with_index do |v, i|
  if max == v
    as_as = as.dup
    as_as.delete_at(i)
    puts as_as.max
  else
  	puts max
  end
end