n = gets.to_i
first = -1
second = -1

A = Array.new(n) do
  gets.to_i.tap do |i|
    if first < i
      second = first
      first = i
    elsif second < i
      second = i
    end
  end
end

A.each do |a|
  if a == first
    puts second
  else
    puts first
  end
end
