n = gets.to_i
a = n.times.map{gets.to_i}

max_num = a.max
max_2_num = a.reject{|e| e == max_num}.max.to_i

max_indexes = a.map.with_index{|e, i| e == max_num ? i : nil}.compact

a.each_with_index do |e, i|
  if max_indexes.size == 1 && max_indexes[0] == i
    puts max_2_num
  else
    puts max_num
  end
end