#!/usr/bin/ruby
#encoding: utf-8

#input
n = gets.to_i
a = Array.new(n)
(0..n-1).each do |i|
  a[i] = gets.to_i
end

# compute
a2 = a.sort.reverse

(0..n-1).each do |i|
  if a[i] != a2[0] then
    puts a2[0]
  else
    puts a2[1]
  end
end