N = gets.to_i
A = N.times.map { |_| gets.to_i }
first = A.max
first_count = A.sort_by { |v| -v }[0,2].uniq.length == 2 ? 1 : 2

tmp = A.dup.tap { |v| v.delete(first) }
second = tmp.max

A.each do |v|
  puts (v != first) || (v == first && first_count == 2) ? first : second
end
