n = gets.to_i
array = []
n.times { array.push(gets.to_i) }

m = array.max
cpd = array
cpd.delete(m)
second_m = cpd.max

array.each do |a|
  ans = a
  if a == m
    ans = a
  elsif a < second_m
    ans = second_m
  end

  puts ans
end
